You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When invoking the agent I want to pass the request context(some additional attributes) to agent so that I can access it from ToolContext and Agent prompts. When creating the session I can do this by passing an object to create_session method's state parameter like below.
session = await session_service.create_session(
app_name=APP_NAME,
user_id=USER_ID,
session_id=SESSION_ID,
state= {"request_context": request_context}
)
runner = Runner(
agent=stateful_agent,
app_name=APP_NAME,
session_service=session_service,
)
content = types.Content(role='user', parts=[types.Part(text=query)])
final_response_text = "Agent did not produce a final response." # Default
async for event in runner.run_async(user_id=user_id, session_id=session.id, new_message=content, ):
if event.is_final_response():
if event.content and event.content.parts:
final_response_text = event.content.parts[0].text
elif event.actions and event.actions.escalate:
final_response_text = f"Agent escalated: {event.error_message or 'No specific message.'}"
break
When resuming a session, I am modifying state object directly which was obtained from SessionService, before invoking the Agent like below
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
When invoking the agent I want to pass the request context(some additional attributes) to agent so that I can access it from
ToolContext
andAgent prompts
. When creating the session I can do this by passing an object tocreate_session
method's state parameter like below.When resuming a session, I am modifying
state
object directly which was obtained fromSessionService
, before invoking the Agent like belowBut the documentation does not recommend directly updating the
state
object. https://google.github.io/adk-docs/sessions/state/#a-warning-about-direct-state-modificationSo is there any other solution to set context to Agent than directly modifying
state
object when continuing a session?Beta Was this translation helpful? Give feedback.
All reactions