feat: add STEP_STARTED/STEP_FINISHED AG-UI lifecycle events#124
Closed
jackzhao8886 wants to merge 1 commit into
Closed
feat: add STEP_STARTED/STEP_FINISHED AG-UI lifecycle events#124jackzhao8886 wants to merge 1 commit into
jackzhao8886 wants to merge 1 commit into
Conversation
Add standard AG-UI Step lifecycle events to distinguish reasoning/thinking text from final answer text in the event stream. - Add STEP_STARTED and STEP_FINISHED to EventType enum - Serialize as native StepStartedEvent/StepFinishedEvent in AG-UI protocol - Silently skip step events in OpenAI protocol (no native support) - Warn and fall back to CustomEvent when stepName is missing - Add unit tests for AG-UI serialization and OpenAI skip behavior - Maintain full backward compatibility Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
|
暂时关闭:客户(神州租车)真实诉求是在多步 Agent 场景下区分「中间旁白文本」与「最终正文」。本 PR 提供的 STEP 事件是正确机制,但需先确认客户接入方式——若为托管 SuperAgent/runloop,emit STEP 的产出逻辑需在 runloop 实现(不在本 PR 范围)。待确认后再决定是否重开。 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds first-class AG-UI “Step lifecycle” events (STEP_STARTED / STEP_FINISHED) to the server event model and AG-UI protocol serialization so clients can distinguish intermediate phases (e.g. reasoning) from the final answer within a single run, while keeping the OpenAI protocol behavior unchanged (step events are skipped).
Changes:
- Added
STEP_STARTED/STEP_FINISHEDtoEventTypeand documented their recommended usage in server-facing examples. - Implemented AG-UI serialization into native
StepStartedEvent/StepFinishedEvent, accepting bothstepNameandstep_name(with warning +CustomEventfallback when missing). - Added unit tests covering AG-UI serialization, snake_case input, missing
stepNamefallback, full lifecycle ordering, and OpenAI skip behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unittests/server/test_step_events.py | Adds focused unit tests for AG-UI step lifecycle serialization and OpenAI protocol skipping behavior. |
| agentrun/server/server.py | Updates public docstring example to use AgentEvent and stepName for step lifecycle events. |
| agentrun/server/openai_protocol.py | Explicitly skips step lifecycle events during OpenAI stream formatting. |
| agentrun/server/model.py | Adds new EventType values and expands documentation examples for step lifecycle events. |
| agentrun/server/agui_protocol.py | Encodes STEP_STARTED / STEP_FINISHED into native AG-UI step events (or warns + falls back to CustomEvent). |
| agentrun/server/init.py | Updates module-level usage example to prefer step lifecycle events over custom step events. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+12
to
+19
| from agentrun.server import ( | ||
| AgentEvent, | ||
| AgentRequest, | ||
| AgentRunServer, | ||
| AGUIProtocolHandler, | ||
| EventType, | ||
| OpenAIProtocolHandler, | ||
| ) |
Comment on lines
+781
to
+784
| logger.warning( | ||
| "STEP_STARTED event missing 'stepName' field, falling back to CustomEvent. " | ||
| "Provide data={'stepName': '...'} for standard AG-UI Step lifecycle events." | ||
| ) |
Comment on lines
+796
to
+799
| logger.warning( | ||
| "STEP_FINISHED event missing 'stepName' field, falling back to CustomEvent. " | ||
| "Provide data={'stepName': '...'} for standard AG-UI Step lifecycle events." | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds standard AG-UI Step lifecycle events so agents can distinguish reasoning/thinking output from the final answer output within a single run.
Why
In the AG-UI event stream, multiple text segments currently have no semantic marker — clients can't tell which text is intermediate reasoning vs. the final reply. This adds the AG-UI-native
STEP_STARTED/STEP_FINISHEDlifecycle events to mark named phases (e.g.reasoning,final_answer).Changes
STEP_STARTED/STEP_FINISHEDto theEventTypeenumStepStartedEvent/StepFinishedEventin the AG-UI protocolstepName(camelCase) andstep_name(snake_case) input keysCustomEventwhenstepNameis missingUsage
Test
pytest tests/unittests/server/— 243 passed.🤖 Generated with Claude Code