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
{{ message }}
Repository navigation
Send message to the ADK API and display in the chat/session #3722
In my workflow, an agent is taking input from a user and, in the tool, submits a long-running job to the outside API. API returns "id" of the job, which the user can then use to query information about the job, i.e., if it is completed and similar.
I'm wondering if there is a way to send an API request to the ADK server from the outside, i.e., in my context, I would like to send a message from the outside system to a user that the job has been completed, and (ideally) it displays in real time in the chat window.
When sending data like this, I only see the message when I reload the Web UI (session), and it appears as if it were from a user (not a model) to which the model then responds.
So my questions are:
Can a message be posted as it is from a model (not a user)
Can the update be done in real-time (without reloading the session)
My hunch is that using the user role is important to prod the agent to initiate another conversational turn, and using the types.FunctionResponse message Part instead of text might allow ADK to recognize this is a long-running tool response, and not actually a message from the user that needs to be rendered. This is just based on my recollection from a few months ago though, so I could be off-base here.
@juszzz thanks for the response and your tips, it helped a lot. I managed to send the data back to ADK API, and it handled it correctly. When data is posted to the ADK API, ADK makes a request to the LLM and sends the LLM's response to the chat.
One thing, though, that I haven't managed yet is how to do an update for chat real-time (but maybe that's an issue of ADK Web UI, I didn't check that yet), chat update is displayed only upon session reload.
This is the code snippet I was using for prototyping. I'm leaving it here for future reference.
Within the data that is being sent to the API, there is "adk_data" that would be sent back from the API
asyncdefmy_tool(user_query: str, tool_context: ToolContext) ->dict:
"""A tool that answer user questions :param user_query: user query for which job will be submitted :return: submitted job id and status """# adk data are needed for the request back to the ADK APIadk_data= {
'app_name': tool_context.agent_name,
'user_id': tool_context.user_id,
'session_id': tool_context.session.id,
'function_call_id': tool_context.function_call_id,
'name': 'my_tool', # this needs to correspond to the tool (function) name
}
api_data= {
'adk_data': adk_data,
'api_input_data': {
# data for API itself for example
}
}
# request to the API that submits input as well as ADK dataresp=requests.post(url=os.environ['API_URL'], json=api_data)
ifresp.ok:
job_response=resp.json()
response_data= {
'job_id': job_response['job_id'],
'status': job_response['status'],
}
returnresponse_dataelse:
return {
'status': 'error',
'message': resp.text
}
and this is part from API how data should be send back:
Activity
juszzz commentedon Nov 26, 2025
We prototyped something using the long-running function tool pattern, and found the official docs to be a bit confusing/unhelpful. What worked for us:
We would send a message (with
userrole -- not sure if this is critical or not) to the ADK agent from our outside API once the job was completed:juszzz commentedon Nov 26, 2025
My hunch is that using the
userrole is important to prod the agent to initiate another conversational turn, and using thetypes.FunctionResponsemessagePartinstead oftextmight allow ADK to recognize this is a long-running tool response, and not actually a message from the user that needs to be rendered. This is just based on my recollection from a few months ago though, so I could be off-base here.zdenulo commentedon Nov 27, 2025
@juszzz thanks for the response and your tips, it helped a lot. I managed to send the data back to ADK API, and it handled it correctly. When data is posted to the ADK API, ADK makes a request to the LLM and sends the LLM's response to the chat.
One thing, though, that I haven't managed yet is how to do an update for chat real-time (but maybe that's an issue of ADK Web UI, I didn't check that yet), chat update is displayed only upon session reload.
This is the code snippet I was using for prototyping. I'm leaving it here for future reference.
Within the data that is being sent to the API, there is "adk_data" that would be sent back from the API
and this is part from API how data should be send back:
juszzz commentedon Nov 27, 2025
@zdenulo glad to help. Did you wrap
my_toolin aLongRunningFunctionToolwrapper before providing it to your agent?zdenulo commentedon Nov 27, 2025
@juszzz yes I did