How to handle user uploaded file in multi agent scenario #5340
Replies: 1 comment
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: To stop execution, you can have an agent set Hello! Welcome to ADK. You've asked some great questions about handling multi-agent workflows. Here’s a more detailed breakdown based on your scenario: 1. How to Stop Execution if a File Isn't UploadedYou can control the flow of execution by having an agent decide to terminate the process early. The recommended way to do this is to have an agent set In your case, you could have an agent that runs after your Here's a conceptual example: # In your Fileacceptor or a subsequent agent, you can set a status
if not file_uploaded:
context.state["temp:file_upload_status"] = "failed"
else:
context.state["temp:file_upload_status"] = "success"
context.save_artifact("my_sql_script.sql", file_content)Then, you can create a simple agent to act as a gate: from adk.api import Agent, Context
class StopExecutionAgent(Agent):
async def _run_async_impl(self, context: Context):
if context.state.get("temp:file_upload_status") == "failed":
print("File upload failed. Stopping execution.")
context.end_invocation = TrueBy placing this 2. Using Artifacts to Share FilesYour instinct to use artifacts is spot on! This is the designed best practice in ADK for passing files or large data between agents. [2]
Remember to configure an 3. Artifacts and the Context WindowThis is a key benefit of using artifacts. When you call ADK is designed to manage the context window for you by "lazy-loading" artifact data only when an agent explicitly requests it via Therefore, you do not need to remove the file from the context manually. By using the artifact system, you are already following the correct pattern for efficient context management. [4] I hope this guidance helps you get started with your project! [1] Context in ADK |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am building a multi agent app to analyse the sql script.
I am building a Sequential Agent which has the Fileacceptor agent, followed by the parallel agent.
The parallel agent contains sub agents to process the input file and generate various outputs.
I want to stop the execution of subsequent agents when the file is not uploaded. I want to use the Artifact approach as I have to share the same file multiple times. If I create the artifact, whether the file will be removed from the context window or I have to remove it manually.
I am new to ADK. Guidance required.
Beta Was this translation helpful? Give feedback.
All reactions