Giving an after_agent_callback access to the output_key of my agent #1123
Unanswered
Acevedan117
asked this question in
Q&A
Replies: 1 comment
-
You would use callback_context.state.get("case_management-case_summary", "") However I believe the last time I tried this with an output_key it wasn't added to the state yet by the time after_agent_callback gets ran. Which is arguably not great since accessing it from an after_agent_callback seems like a pretty normal thing devs would want to do with the output_key. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My agent has an output_key which I need to be able to use and pass in as a argument to another function. I'm attempting to use an after_agent_callback to call this function using the output_key from the agent after the agent has been run.
I'm currently unsure of the syntax needed to do this and cannot find documentation on it. Here is the current code:
from google.adk.agents import LlmAgent
from google.adk.agents.callback_context import CallbackContext
from google.genai import types
from agentic_secops.sub_agents.case_manager import prompt
from agentic_secops.tools.soar import (
get_full_case,
assign_case_to_user,
get_entities_in_case_or_alert,
post_case_comment,
check_if_case_exists
)
Callback: Runs after agent completes
def post_summary_as_comment(callback_context: CallbackContext) -> Optional[types.Content]:
summary = callback_context.final_output.get("case_management-case_summary")
#####^^^^(Getting my error here, don't know the proper syntax to do this)^^^^^######
agent_name = callback_context.agent_name
Agent definition
case_management_agent = LlmAgent(
model='gemini-2.0-flash-001',
name='case_management_agent',
description="Handle SOAR case management functions including getting case/alert/event/entity data and interacting with the case wall.",
instruction=prompt.CASE_MANAGEMENT_INSTRUCTIONS,
tools=[
check_if_case_exists,
assign_case_to_user,
get_full_case,
get_entities_in_case_or_alert,
post_case_comment
],
output_key="case_management-case_summary",
after_agent_callback=post_summary_as_comment
)
Beta Was this translation helpful? Give feedback.
All reactions