Replies: 5 comments
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
My hunch is that using the |
Beta Was this translation helpful? Give feedback.
-
|
@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 async def my_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 API
adk_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 data
resp = requests.post(url=os.environ['API_URL'], json=api_data)
if resp.ok:
job_response = resp.json()
response_data = {
'job_id': job_response['job_id'],
'status': job_response['status'],
}
return response_data
else:
return {
'status': 'error',
'message': resp.text
}and this is part from API how data should be send back: adk_url = "http://127.0.0.1:8000/run"
adk_data = {'app_name': 'chat_agent', 'user_id': 'user', 'session_id': 'd44a9855-d4e3-4d1a-9722-5ec20a1b6a25',
'function_call_id': 'adk-b8ff9c21-f56a-445c-afe2-edc546417894', 'name': 'my_tool'}
data = {
'app_name': adk_data['app_name'],
'user_id': adk_data['user_id'],
'session_id': adk_data['session_id'],
'new_message': {
'parts': [
{
'function_response': {
'id': adk_data['function_call_id'],
'name': adk_data['name'],
'response': {'status': 'completed', 'job_id': '12'}
}
}
],
'role': 'user'
}
}
r = requests.post(adk_url, json=data) |
Beta Was this translation helpful? Give feedback.
-
|
@zdenulo glad to help. Did you wrap |
Beta Was this translation helpful? Give feedback.
-
|
@juszzz yes I did |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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.
I've tried this code snippet
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:
Beta Was this translation helpful? Give feedback.
All reactions