Skip to content

Commit 7d50564

Browse files
authored
Add async with self in agent_to_a2a (#2266)
1 parent 01c550c commit 7d50564

File tree

1 file changed

+3
-3
lines changed
  • pydantic_ai_slim/pydantic_ai

1 file changed

+3
-3
lines changed

pydantic_ai_slim/pydantic_ai/_a2a.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@
5959

6060

6161
@asynccontextmanager
62-
async def worker_lifespan(app: FastA2A, worker: Worker) -> AsyncIterator[None]:
62+
async def worker_lifespan(app: FastA2A, worker: Worker, agent: Agent[AgentDepsT, OutputDataT]) -> AsyncIterator[None]:
6363
"""Custom lifespan that runs the worker during application startup.
6464
6565
This ensures the worker is started and ready to process tasks as soon as the application starts.
6666
"""
67-
async with app.task_manager:
67+
async with app.task_manager, agent:
6868
async with worker.run():
6969
yield
7070

@@ -93,7 +93,7 @@ def agent_to_a2a(
9393
broker = broker or InMemoryBroker()
9494
worker = AgentWorker(agent=agent, broker=broker, storage=storage)
9595

96-
lifespan = lifespan or partial(worker_lifespan, worker=worker)
96+
lifespan = lifespan or partial(worker_lifespan, worker=worker, agent=agent)
9797

9898
return FastA2A(
9999
storage=storage,

0 commit comments

Comments
 (0)