Skip to content

Feature Request: Synchronous Calls #934

@JonathanRayner

Description

@JonathanRayner

I would love it if I had the option use the library entirely with synchronous calls. This way, I have full freedom to enable or disable this, pursue other concurrency models, and would have less issues interfacing with other libraries that are opinionated about open event loops.

Unfortunately, run.sync doesn't solve this. I'd actually prefer if synchronous calls were a 1st class citizen and there was a thin wrapper or arg to make things async instead of vice versa. Unfortunately, I understand that this isn't necessarily easy to express in python, meaning it often leads to two full copies of the api for sync and async. Still, I think there's a good reason this is available in e.g. OpenAI's client.

Addendum (feel free to ignore)

More broadly (please excuse if I'm overstepping my bounds), but I wonder a bit if this is a downstream issue of a broader problem with what the identity of this library is. When I read:

Agent Framework / shim to use Pydantic with LLMs

PydanticAI is a Python agent framework designed to make it less painful to build production grade applications with Generative AI.

Every agent framework and LLM library in Python uses Pydantic, yet when we began to use LLMs in Pydantic Logfire, we couldn't find anything that gave us the same feeling.

I think "Oh cool, the Pydantic team is making an agent framework. I'll use that if I need to do something involving agentic workflows, probably overkill otherwise."

But then when I hear:

PydanticAI

PydanticAI is a Python Agent Framework designed to make it less painful to build production grade applications with Generative AI.

We built PydanticAI with one simple aim: to bring that FastAPI feeling to GenAI app development.

My thought is, "Oh! Amazing! The Pydantic team is going bring that 'minimal, just works, clean' feel compared to lots of other recent general AI frameworks."

Personally I would love a philosophy that is something like

  1. PydanticAI: makes input/output data validation easy, standardize ways of calling apis, standardize logging/observability (or connect to other observability tools)
  2. PydanticAgents or PydanticWorkflows w/e: build complex workflows, graphs, etc. on top of PydanticAI
  3. ???

Overall, I'm sort of hoping for Pydantic <-> PydanticAI and FastAPI <-> PydanticAgents or something like this. But right now they're blending together. I think the tension between these two viewpoints leads to some design consequences:

  • As a user, it's easier for me to build agent workflows on top of what I call PydanticAI + some features of PydanticAgents being implemented, but it's much harder to build on top of what I call fully-featured PydanticAgents with only some of PydanticAI implemented. A key example of this would be the decision prioritize more agentic features, while multi-modal support still doesn't feel particularly clean. If thinking generally about AI, multi-modal input would be one of the first things I think should be supported, before more complex features.
  • Maybe if you're thinking agents, then it might be "obvious" that async is a reasonable default (maybe not). But if thinking just "good foundation for ai" this would be an optional extra feature request.
  • Certainly the default usage of just passing things into an Agent works great and feels clean. But also there are situations when it seems like you need to create a Client just to pass it into a Model just to pass that into an Agent. Maybe this is outdated docs, but if not, that doesn't feel right. Using a custom endpoint in the OpenAI client outside of this library requires just passing the different endpoint and api key as args, not instantiating 3 classes. It's not a big deal, but I wonder if more things like this will happen if Agent is the first class citizen, instead of viewed as built "on top of" PydanticAI.
  • The choice to have a simple centralized way to call loads of providers (as opposed to "bring your own client"), great data validation on inputs and outputs, and logfire makes it feel like this is a general foundation for AI, not just a way to run agent workflows (and that's great!).
  • Having more of a separation between the philosophy of PydanticAI and PydanticAgents also helps with possible paradigm shifts. Maybe in a year or two, we won't really be thinking about "agents," maybe we will. But we'll always want full-featured standards for calling AI apis, data validation in and out, logging, observability, etc.
  • Said another way: what defines an agent? Is it a client + state? Model + state? Or just a client or a model? A useful coordination point of many different abilities? I think it might be useful to have building blocks to create many different types of agents in the long run.

Thanks for all the hard work, curious what you think. I wouldn't write this if I wasn't super excited about this library!

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions