Live data from Hacker News

Building your own CLI coding agent with Pydantic-AI

martinfowler.com

31–40 of 43 posts

Re: Building your own CLI coding agent with Pydantic-AI

#31
post #12
post #8

These abstractions are nice to not get locked in with one llm provider - but like with langchain - once you use some more niche feature the bugs do shine through. I tried it out with structured output for azure openai but had to give up since somewhere somewhat was broken and it's difficult to figure out if it's the abstraction or the library of the llm provider which the abstraction uses. Nevertheless i would strong…

Pydantic AI maintainer here! Did you happen to file an issue for the problem you were seeing with Azure OpenAI? The vast majority of bugs we encounter are not in Pydantic AI itself but rather in having to deal with supposedly OpenAI Chat Completions-compatible APIs that aren't really, and with local models ran through e.g. Ollama or vLLM that tend to not be the best at tool calling. The big three model providers (Ope…

Thanks for working on pydantic-ai. I digged up the issue - it seems to have been fixed with the recent releases related to how strictness is handled.

Re: Building your own CLI coding agent with Pydantic-AI

#32

I really wish Pydantic invested in... Pydantic, instead of some AI API wrapper garbage. I've been using it a lot lately and anything beyond basic usage is an absolute chore.

I wish Python would improve to bridge the gaps between pydantic and dataclasses, so that we don't have to rely on pydantic. It's too foundational a piece to not be part of the core python anymore

> I wish Python would improve to bridge the gaps between pydantic and dataclasses, so that we don't have to rely on pydantic. It's too foundational a piece to not be part of the core python anymore

I agree on the first part, but Pydantic is not important to Python. It's important to a lot of people, but it's absolutely unnecessary.

Re: Building your own CLI coding agent with Pydantic-AI

#33

I really wish Pydantic invested in... Pydantic, instead of some AI API wrapper garbage. I've been using it a lot lately and anything beyond basic usage is an absolute chore.

I wish Python would improve to bridge the gaps between pydantic and dataclasses, so that we don't have to rely on pydantic. It's too foundational a piece to not be part of the core python anymore

[dead]

Re: Building your own CLI coding agent with Pydantic-AI

#34

I really wish Pydantic invested in... Pydantic, instead of some AI API wrapper garbage. I've been using it a lot lately and anything beyond basic usage is an absolute chore.

I wish Python would improve to bridge the gaps between pydantic and dataclasses, so that we don't have to rely on pydantic. It's too foundational a piece to not be part of the core python anymore

It's just de/serialisation. IMO if you feel totally dependent on a single library for doing this for you then you're doing too much in that layer. This should be a tiny thin layer right at the edge of your application just for getting data in/out. I've seen people build almost their entire application in Pydantic classes. You're doing it wrong.

I don't know why people like this pattern of "fat" classes with built in de/serialisation/persistence logic at all. It makes so much more sense to have that at the edge and build entities and/or value objects directly. Using stuff like Pydantic or Django ORM you either end up completely coupling domain logic to serialisation logic, or you end up manually writing data mappers to/from your domain when you could have just used, for example, cattrs or SQLAlchemy. I guess it's the "easy vs simple" thing.

Re: Building your own CLI coding agent with Pydantic-AI

#35

Am I correct in thinking that it would cost more if you used your own agent with Sonnet 4 than going through Claude Code since you would have to go through the Anthropic API? What models do folks with custom agents usually use? And what kind of prompts seem to provide the same responses that Claude Code would give you?

Claude Code is free if you have a subscription to Claude. It's much more affordable than using the API key directly.

Re: Building your own CLI coding agent with Pydantic-AI

#36

Am I correct in thinking that it would cost more if you used your own agent with Sonnet 4 than going through Claude Code since you would have to go through the Anthropic API? What models do folks with custom agents usually use? And what kind of prompts seem to provide the same responses that Claude Code would give you?

Claude Code is free if you have a subscription to Claude. It's much more affordable than using the API key directly.

Doubt it, based on my ccusage output. I do about the monthly charge in tokens in a day.

Re: Building your own CLI coding agent with Pydantic-AI

#37
post #32

Earlier quoted context omitted.

I wish Python would improve to bridge the gaps between pydantic and dataclasses, so that we don't have to rely on pydantic. It's too foundational a piece to not be part of the core python anymore

> I wish Python would improve to bridge the gaps between pydantic and dataclasses, so that we don't have to rely on pydantic. It's too foundational a piece to not be part of the core python anymore I agree on the first part, but Pydantic is not important to Python. It's important to a lot of people, but it's absolutely unnecessary.

its the ideal way to do structured outputs with LLMs and Python has become the default language for AI applications. I would wager that structured outputs are probably the no.1 usecase in AL applications

Re: Building your own CLI coding agent with Pydantic-AI

#38

Earlier quoted context omitted.

I wish Python would improve to bridge the gaps between pydantic and dataclasses, so that we don't have to rely on pydantic. It's too foundational a piece to not be part of the core python anymore

It's just de/serialisation. IMO if you feel totally dependent on a single library for doing this for you then you're doing too much in that layer. This should be a tiny thin layer right at the edge of your application just for getting data in/out. I've seen people build almost their entire application in Pydantic classes. You're doing it wrong. I don't know why people like this pattern of "fat" classes with built in…

would you say the same of SQLModel? Which I think is an ideal solution (theoretically), better than SQLAlchemy

Re: Building your own CLI coding agent with Pydantic-AI

#39
post #13

Earlier quoted context omitted.

In this example, you get locked into pydantic_ai, another proprietary provider.

How do you mean? Pydantic AI (which I'm a maintainer of) is completely open source. We do have a proprietary observability and evals product Pydantic Logfire ( https://pydantic.dev/logfire ), but Pydantic AI works with other observability tools as well, and Logfire works with other agent frameworks.

thanks for clarifying. I guess my comment was more directed to the fact that pydantic, the company is 1) VC backed 2) Unclear how/when/what you will monetize 3) how that will affect the open source stuff.

I strongly believe you guys should be compensated very well for what you bring to the ecosystem but the probability of open source projects being enshittified by private interests is non-trivially high.

Re: Building your own CLI coding agent with Pydantic-AI

#40

Earlier quoted context omitted.

It's just de/serialisation. IMO if you feel totally dependent on a single library for doing this for you then you're doing too much in that layer. This should be a tiny thin layer right at the edge of your application just for getting data in/out. I've seen people build almost their entire application in Pydantic classes. You're doing it wrong. I don't know why people like this pattern of "fat" classes with built in…

would you say the same of SQLModel? Which I think is an ideal solution (theoretically), better than SQLAlchemy

SQLModel is even worse as it couples everything together. It's only good for basically building a JSON interface on top of a database. I guess it could be useful for a very basic web app. But the moment you start needing logic on the backend beyond basic read/write permissions you're screwed. At that point you either rewrite or proceed to build a big ball of mud.

In my experience backends never stay simple enough for SQLModel so you might as well decouple from the get go. If it's literally just copy/paste between SQLAlchemy models and Pydantic just do the copy/pasting. Get an LLM to do it if you have to. It will be worth it in the long run. You'll want to change your db schema without breaking your API.

Post reply on HN