adk: nil event from custom agent is converted into panic error
- Dominant language
- Go
- Stars
- 13k
- Forks
- 1.1k
- Avg merge
- 4h 6m
- Merged PRs (30d)
- 41
Description
**Describe the bug**
When a custom Agent yields a nil event through its AsyncIterator, the ADK flow wrapper dereferences the event while assigning RunPath. The nil pointer panic is recovered and exposed as a generic panic error with a stack trace.
This affects both the Message and AgenticMessage flow paths. For an Agent wrapped as an AgentTool, the caller receives the panic error instead of a clear contract error.
**To Reproduce**
1. Implement a custom Agent whose Run method sends nil before closing its AsyncGenerator.
2. Wrap it with NewAgentTool or execute it with Runner.
3. Consume the returned iterator.
4. Observe a recovered nil-pointer panic originating in adk/flow.go.
Minimal behavior:
```go
iter, gen := adk.NewAsyncIteratorPair[*adk.AgentEvent]()
go func() {
defer gen.Close()
gen.Send(nil)
}()
return iter
```
**Expected behavior**
The framework should reject a nil event at the central flow boundary and return an actionable error such as:
`agent 'name' returned nil event`
It should not rely on panic recovery for invalid custom-agent output.
**Version**
Current main before the fix: `9d983b36`
**Environment**
```
go version go1.25.12 darwin/arm64
GOOS=darwin
GOARCH=arm64
```
**Additional context**
I have a small fix with regression coverage for both Message and AgenticMessage paths. The full `go test ./adk/...` suite and focused race-detector tests pass.
Contributor guide
Research direction
Start in adk/flow.go at the flow boundary where RunPath is assigned, then trace the Message and AgenticMessage paths used by Runner and NewAgentTool. Add regression coverage for a custom agent sending a nil event, and run the focused race-detector tests plus go test ./adk/...; done means an actionable agent-name error is returned instead of a recovered panic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- ai, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100