google / google/adk-docs

Loop agent overwrites state's output key when invoking exit_loop tool

Open
#1,403 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
1.5k
Forks
1.3k
Avg merge
7d 1h
Merged PRs (30d)
34

Description

**Describe the bug**

This is a bug in the [LoopAgents demo](https://google.github.io/adk-docs/agents/workflow-agents/loop-agents/). The demo shows an iterative writing pipeline.

1. An initial writer agent produces an output and assigns it to a state key CURRENT_DOC.
2. LoopAgent
a. A LLMAgent writes feedback and outputs it to another state key. If no feedback, it outputs COMPLETION_PHRASE
b. A LLMAgent uses that feedback to re-write the document, outputting it to the same state key CURRENT_DOC. If COMPLETION_PHRASE is present in feedback, it doesnt output anything and calls `exit_loop` tool.

**To Reproduce**

Steps to reproduce the behavior:
1. Copy/run [LoopAgents demo](https://google.github.io/adk-docs/agents/workflow-agents/loop-agents/) in adk ui (`adk web --log_level DEBUG --port 8000 path/to/agent/dir`
2. Run the agent with some topic.
3. Observe that there is no final output. Observe that `state[current_document]` is now an empty string when the invocation ends.

**Expected behavior**

The last unmodified state value is propagated through the end of the loop. This seems to be the intent of the demo, but it doesn't work.

**Screenshots**

The state variable during intermediate events in the agent invocation:

Image

The final state is empty:

Image

**Versions**

- OS: Linux
- ADK version: 1.25.1
- Python version: 3.11

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.