-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Question
Hi,
I have a need to access the scope of a starlette request that has triggered the agent run, within the tool calls. I can't figure out how to do this using dependency injection as it currently exists, as I want to access an object that is new for each agent run. This is because we have fine grained access control to data for different users, and my custom middleware for Starlette is inserted into the FastA2A instance, attaching user specific access details on each request into the scope of the Starlette Request.
Is this possible as is, or is this a feature request? From what I see, it isn't yet possible. But can anyone think of a workaround? Is this something that should be updated in FastaA2A? Since Agent runs happen independent of the request stack, the only way I see it working is if the scope/request is inserted as metadata for the task.
Additional Context
I would ideally have something like:
def foo(ctx: RunContext):
scope = ctx.request.scope
....
agent = Agent(
...,
tools=[Tool(foo, takes_ctx=True)]
)
app = agent.to_a2a(...)