-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Clarify usage of agent factories #3592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Clarify that agents can be produced by a factory function if preferred.
|
|
||
| !!! tip "Agents are designed for reuse, like FastAPI Apps" | ||
| Agents are intended to be instantiated once (frequently as module globals) and reused throughout your application, similar to a small [FastAPI][fastapi.FastAPI] app or an [APIRouter][fastapi.APIRouter]. | ||
| Agents can be instantiated once as a module global and reused throughout your application, similar to a small [FastAPI][fastapi.FastAPI] app or an [APIRouter][fastapi.APIRouter], or be created dynamically by a factory function like `get_agent('agent-type')`, whichever you prefer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the factory function idea come from? I don't think we need to mention that specifically. Going by https://pydanticlogfire.slack.com/archives/C083V7PMHHA/p1763775638553099, we mostly need to make it clear that it's totally fine to create an agent dynamically at any point of your application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
factory function + example seemed the clearest wording to me to communicate that you can also make them dynamically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be created dynamically, for example, by a factory function like `make_agent('agent-type')`, whichever you prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsfaccini I think that's still very prescriptive, as dynamic can also just mean you can build it inside a FastAPI endpoint function on the fly, no factory function needed. The intent of this change is too loosen our wording to be less prescriptive and basically say "whatever you want is fine", not to change "do it this way" to "do it this way or that way" when there are many other possible ways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!!! tip "Agents are designed for reuse, like FastAPI Apps"
You can instantiate one agent and use it globally throughout your application, as you would a small [FastAPI][fastapi.FastAPI] app or an [APIRouter][fastapi.APIRouter], or dynamically create as many agents as you want. Both are valid and supported ways to use agents.
Clarify that agents can be produced by a factory function if preferred.