Open
Description
Description
Extracted from this issue #2086 since this is more generic
OpenAI has a background mode that works something like this
from openai import OpenAI
from time import sleep
client = OpenAI()
resp = client.responses.create(
model="o3",
input="Write a very long novel about otters in space.",
background=True,
)
while resp.status in {"queued", "in_progress"}:
print(f"Current status: {resp.status}")
sleep(2)
resp = client.responses.retrieve(resp.id)
print(f"Final status: {resp.status}\nOutput:\n{resp.output_text}")
Since Agents can also be really long running. We can think of running Agents in the background.
I was thinking of adding a new API
agent = Agent(...)
resp = agent.start() # similar API to run, but this runs the agent as a background task
resp can still be an instance of AgentRun
, and we can support the idea of background tasks in AgentRun
itself and add a status property on it.
You would then check the status of the agent run using.
resp.status
The agent.run
can then be thought of as just waiting for the agent to finish.
Implementation Thoughts
I am still not too sure on the implementation details, but most likely this might end up with pydantic_ai having some kind of task queue/system where agents can run in background.