-
Notifications
You must be signed in to change notification settings - Fork 519
feat: Step through execution with runs #2290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @marklysze , this is a great feature,
event look very pretty in terminal, and the Custom Event feature and the event filter in StepController are Awesome.
the turn count shown at the end of chat, is very helpful feature in orchestration design.
good documentation.
great design.
Approving this Pull request.
the only change I would suggest, is to change
step_on: Sequence[type] | None = None, ---> step_on: Sequence[type[BaseEvent] | None = None , aiming for Custom event type check.
Merry Christmas :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, @marklysze ! Really impressive
But, I have some doubts about suggested public API
Why you prefer current impl:
with agent.run(..., step_mode=True) as response:
while True:
event = response.step()
if event is not None:
...Instead of alternative API without changes in current behavior?
for msg in agent.run_iter(...):
... # msg always `BaseEvent` type instead of `BaseEvent | None`
Appreciate this thought and it's a better Pythonic approach with the iterator, and I think the clean-up that I used the context manager for, is better your suggested way. I am working through a conversion to |
|
Thanks @Lancetnik and @priyansh4320 for your feedback and suggestions - I have refactored to new iterators, |
* Step through run * Notebook tweak * Custom events notebook * Pre-commit tidy * Fix mermaid diagrams * Correctly detect async send * Constrain type * Conversion to dedicated iterator run functions * Update documentation * Add to init and correct docs * Correct notebook docs * Remove examples from docstrings
* implement fn target test file * add documentation for FunctionTarget, udpate example notebook * Update sonnet model to 4.5 (#2186) * Feat/a2a hitl (#2187) * feat: add A2A Human in the loop support * chore: bump version * refactor: simplify client logic * refactor: support multiturn * lint: remove mypy ignores * tests: add Terminate human_input tests * docs: update A2A Hitl server * docs: Update Agent-to-Agent to Agent2Agent branding (#2193) Update terminology across documentation to use consistent "Agent2Agent" branding instead of "Agent-to-Agent" or "agent-to-agent". Changes: - A2A documentation index page (title, heading, protocol link) - Group chat resuming documentation - Research talk abstract (Nov 2024) This provides consistent branding for the Agent2Agent (A2A) communication protocol throughout the documentation. Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> * Fix: OpenAI , azure, gemini tests and update credentials (#2188) * Update sonnet model to 4.5 * fix: openai, gemini realtime * update: credentials * fix: realtime agent tool registry * fix: assistant agent test * [skip ci] docs: fix outdated docs * fix: credentials * fix: azure tests * [skip ci] docs: fix outdated docs * fix: pre-commit * fix: dev setup mdx Revert "Merge pull request #2194 from ag2ai/docs/jgr-autofix-ag_2-2188" This reverts commit 3aa474c, reversing changes made to 4d9de80. fix: user-guide --------- Co-authored-by: Mark Sze <mark@sze.family> Co-authored-by: joggrbot[bot] <107281636+joggrbot[bot]@users.noreply.github.com> * Update LLM configuration methods in documentation (#2195) Reorganized LLM configuration methods, the 2 parts were written oppositely * [Feature] New client architecture with OAI completions API client (#2182) * fix client response protocol init commit * fix mypy errors * Unified Rich Response client architecture Init commit * made the role and status fields extensible in the unified response * OpenAIResponsesClient v2 init commit * OpenAIResponsesClient support for basic features * Fix groupchat which normalize content to str * [MISC] Fix mypy errors (#2167) * fix client response protocol init commit * fix mypy errors * fix: claude-code-review action for forked branches (#2171) * Update integration test * Fix new oai cient name to completions * Update notebook * Update integration test * fix client response protocol init commit * fix mypy errors * [MISC] Fix mypy errors (#2167) * fix client response protocol init commit * fix mypy errors * Add tests with real data for OpenAICompletionsClient * Add better support for GenericContent * Add support for UserRoleEnum * clean up * Update * Remove non str handling from chat completion api * refactor to use getattr * Remove message_retrieval from client v2 protocol * Add Content type enum * Add migration plan documentation * Add text property to content blocks * Add V1 client compatibility notebook * Notebook tweaks * pre-commit tidy --------- Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> Co-authored-by: Mark Sze <mark@sze.family> Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> * fix: chromadb and sentence-transformers package versions (#2202) * chromadb and sentence-transformers package versions * Agent Builder test credentials * Test tweaks * feat: add gpt 5.1 , codex and search models configs (#2205) * DocAgent documentation fixes, documentation fix for tables (#2206) * Events for handoffs (#2093) * Handoff events for AfterWorks, OnContextCondition, and LLM-based OnCondition * Remove uuid from event init parameters * Add ReplyResult transition event, move event tests out of group tool executor tests * Consolidate transition events into single file --------- Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> * [Enhancement] Replace Golden_Retriever image url with simple images with base64 str (#2207) * Replace Golden_Retriever image url with simple images with base64 encoding * Update tests * feat: add addr information to 404 error (#2210) * Add Pydantic Structured Output to OpenAICompletionsClient (#2208) Co-authored-by: Qingyun Wu <qingyun0327@gmail.com> Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> * added logic to extract text from ThinkingBlock (#2139) * added logic to extract text from ThinkingBlock * Reorder imports in anthropic.py * added unit test for thinking block * Fix type checks to use isinstance for content * Fix trailing whitespace in test_anthropic.py --------- Co-authored-by: Yixuan Zhai <6344553+randombet@users.noreply.github.com> Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> * feat: A2A Client interceptors support (#2231) * [Feature] Anthropic structured output with JSON output (#2220) * Anthropic Native structured output support iniit commit * Verified fallback json is working * add strict tool use cases and fix message format * Fix groupchat tests * Add error details to request exception logging * Enforce correct SDK use case * Fix bugs on from client side * Refactor * Fix most of agentchat integration tests * Add notebook example * Support ThinkingBlock * Update notebook --------- Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> * fix: missing await on async calls and bedrock keyerror (#2221) * fix: keyerror in bedrock client on format tool * fix: missing await for async call * test: integration test * Fix: Use github static image to replace wiki image for testing (#2236) * Use github static image to replace wiki image for testing * Correct test assert --------- Co-authored-by: Mark Sze <mark@sze.family> * Fix No Upper Bound on Dependency Version for google-sdk (#2237) * feat:[response_format] Bedrock client structured output (#2226) * feat: response format support on bedrock client * feat: add test and documentaion for bedrock response format * add front matter to safeguard notebook --------- Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> Co-authored-by: Mark Sze <mark@sze.family> * fix: Using Structured Outputs and Streaming with OpenAI client fails (#2234) * OpenAI Chat Completions client structured output with streaming fix * Avoid streaming logic with OpenAI and structured outputs * Tidy * Tidy and tests * Defensive use of usage attribute * Integration tests * Test Transition fix * Test file fix * Bump version from 0.10.1 to 0.10.2 (#2239) * [Enhancement]Fix OAI V2 client tool call extract logic from message_retrieval (#2214) * Fix tool call extract logic from message_retrieval * Update reasoning support for v2 client * Use github img file to replace wiki img file for testing * Fix integration tests * Fix test from local * Test updates to o4-mini from o1-mini (deprecated) --------- Co-authored-by: Mark Sze <mark@sze.family> * feat: Route event printing through logging (#2217) * feat: Route event printing through logging * add licence headers * fix: tests * fix: move code * docs: add logging events * fix: pre-commits * Fix handling of img tags for MultiModalConversableAgent (#2247) * chore: Version bump of google-genai (#2240) * Bump max google-genai version * Add new field to Gemini function calling config class * feat: Add OpenAI GPT 5.2 support (#2250) * feat: gpt5.2 support * feat: add xhigh resoning effort support * Reasoning effort to OpenAI Responses client * Fix test * Test updates for OpenAI SDK alignment * pre-commit tidy --------- Co-authored-by: Mark Sze <mark@sze.family> * Documentation: fix llmconfig assignments and include bedrock API key in config (#2252) * Fix: Validation Error on aysnc default_auto_reply (#2256) * fix: validation error on async default_auto_reply * bugfix: validation error on async default_auto_reply * fix: correct long-living tasks processing (#2255) * fix: correct long-living tasks processing * lint: fix mypy * feat:[response API] GPT 5.1 apply_patch tool call support (#2213) * feat: add gpt 5.1 apply_patch tool call support to responses API * test: apply_patch tool call gpt 5.1 * cleanup * fix: apply_patch_tool_output * fix: apply patch tool output * test:[tool] apply patch * tests: openai responses, apply patch tool * document: notebook example * fix: workspace directory design * fix: allowed path * fix: prints * test: workspace dir and allowed path * feat: move openai specific configs to ConfigEntries * feat: update document * fix: tests and documentation * fix: pre-commits * fix: remove prints * fix: remove wrong docstring * fix: docstrings * fix: workspace is none * fix: nonetype error in notebook environment * fix: notebook environment patches * feat: add sync patches * feat: add sync patch support * fix pre-commits * tests: async patches * fix: pre-commits * fix: apply update patch sync * fix: async patch calls in notebook * fix: recipient messages * fix: normalize messages for responses client * fix: add groupchat example for apply_patch * test: normalize message * fix: pre-commits * Notebook tweak * Remove unused project.py * Revert anthropic.py * Reset anthropic.py to main 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: notebook * fix: remove debug prints * fix: normalization on apply patch calls * test: normalization * remove duplicated tests * fix: move apply patch tool to tools/experimentals * fix: improve docstrings * docs: apply_patch_tool.mdx * Ffx: path validation security * fix: fnmatch * fix: aiofiles for true async * fix: type ignores * fix: operation type validation * fix: tests * fix: use run and initiate_chat in notebook * fix: code utils * fix: test * fix: delete apply patch.mdx * fix: readme * fix: readme * Update * Remove unnecessary doc * fix: notebook and ConfigEntry * Documentation: filter notebook * Remove wrong documentation --------- Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> Co-authored-by: Mark Sze <mark@sze.family> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yixuan Zhai <6344553+randombet@users.noreply.github.com> * fix: use Schema objects for Gemini FunctionDeclaration parameters (#2260) * use Schema objects for Gemini FunctionDeclaration parameters * Handle property values that are $ref * Remove missing type field logger message * Tidy: type hints, return types * feat: ThinkingConfig support gemini (#2254) * feat: add thinking config support * test: thinking config * doc: add notebook example * fix: pre-commit * fix: descriptions * update: google-gemini.mdx documentation * Updated Notebook example, added gemini-3-flash-preview to notebook, updated Gemini pricing, added tests * Notebook tweaks for thoughts and installation * fix: remove medium thought to high --------- Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> Co-authored-by: Mark Sze <mark@sze.family> * Support for thought signatures in functions for Gemini 3 models (#2267) * [Fix] Tool format with Anthropic Beta APIs (#2261) * Fix tool format with Anthropic Beta APIs * Fix integration test * Refactor duplicated logic --------- Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> * Fix path for windows apply_patch test (#2269) * Document: update ipynb with LLMConfig(config_list=[]) (#2264) * Document: update ipynb with LLMConfig(config_list=[]) * fix: delete cell file * [skip ci] docs: fix outdated docs * fix: joggr pre-commit --------- Co-authored-by: joggrbot[bot] <107281636+joggrbot[bot]@users.noreply.github.com> Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> * fix: bedrock structured outputs tool choice (#2251) * fix: structured outputs * fix: remove debug prints * fix: __structured output not found error * fix: use run method in notebook * test: integration test * fix: bedrock test assertions * fix: add normalisation for strict structured tooling * fix: test * fix: test --------- Co-authored-by: Qingyun Wu <qingyun0327@gmail.com> Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> * Version 0.10.3 bump (#2270) * Fix front_matter in notebook (#2271) * fix: Set agents on RunResponse for group chat runs (#2274) * Set agents on RunResponse for group chat runs * Fix for covariant * chore: Add @runtime_checkable to RunResponseProtocol (#2273) * Add runtime_checkable to RunResponseProtocol * pre-commit tidy * Tests * Fix: unexpected chars in documentation (#2282) * fix: formatting * fix: illegal charectors and formatting * fix: claude reviews (#2285) * Documentation: blogpost Logging events (#2286) * documentation: Blogpost MultiMCPSessionManager (#2287) * Documentation: Fix A2A Document Parsing Errors (#2281) * Avoid pydantic deprecation warnings on import (#2272) * Avoid pydantic deprecation warnings on import * fix: format code to pass ruff pre-commit checks Add required blank lines before method decorators in conditional blocks and format assert statement to single line per ruff formatting rules. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: handle ImportError in test_execute_one_wolfram_query When wolframalpha package is not installed, WolframAlphaAPIWrapper raises ImportError instead of ValueError. This test now catches both exceptions to properly handle the case when the optional dependency is missing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> Co-authored-by: Claude <noreply@anthropic.com> * Handle missing A2A task start events (#2275) * fix(a2a): guard missing task startup * Fix mypy redundant cast in A2A client * Remove assertion for started_task in client.py Removed assertions for started_task in connection logic. * test: add coverage for agent_card=None scenario in A2A client Add two new test cases to cover the branch where agent_card is None: - test_streaming_raises_when_no_task_and_no_agent_card - test_polling_raises_when_no_task_and_no_agent_card This improves patch coverage from 40% to ~100%. * fix: remove unused cast import to pass pre-commit check The cast import was no longer needed after refactoring the code to use explicit None checks instead of type casting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Pastukhov Nikita <diementros@yandex.ru> Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> Co-authored-by: Claude <noreply@anthropic.com> * Documentation: fix navigation logging events (#2280) * Documentation: fix navigation logging events * fix: misc to observability * Docs/unify referenceagent (#2268) * docs: unify DocAgent reference docs under single section * docs: unify DocAgent reference pages under a single section * docs: update Mintlify navigation and fix DocAgent links * Update mint-json-template.json.jinja * Update docagent-performance.mdx --------- Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> * Docs/fix docagent performance nav (#2294) * docs: unify DocAgent reference docs under single section * docs: unify DocAgent reference pages under a single section * docs: update Mintlify navigation and fix DocAgent links * Update mint-json-template.json.jinja * Update docagent-performance.mdx * Update mint-json-template.json.jinja Corrected the docagent-performance path * docs: rename DocAgent page and fix navigation path * docs: revert DocAgent file rename to restore working navigation * Update docagent-performance.mdx --------- Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> * fix: banner image (#2295) * fix: banner image * fix: space * fix: could not aprse acorn (#2279) * feat: Step through execution with runs (#2290) * Step through run * Notebook tweak * Custom events notebook * Pre-commit tidy * Fix mermaid diagrams * Correctly detect async send * Constrain type * Conversion to dedicated iterator run functions * Update documentation * Add to init and correct docs * Correct notebook docs * Remove examples from docstrings * fix typo * fix: Documentation improve * fix: filename convention * Notebook update for run and front matter * Test updates --------- Co-authored-by: Qingyun Wu <qingyun0327@gmail.com> Co-authored-by: Mark Sze <66362098+marklysze@users.noreply.github.com> Co-authored-by: Pastukhov Nikita <nikita@pastukhov-dev.ru> Co-authored-by: sam-ag2 <samuel@ag2.ai> Co-authored-by: Priyanshu Yashwant Deshmukh <priyanshu@ag2.ai> Co-authored-by: Mark Sze <mark@sze.family> Co-authored-by: joggrbot[bot] <107281636+joggrbot[bot]@users.noreply.github.com> Co-authored-by: Ruchita-debug <55085634+Ruchita-debug@users.noreply.github.com> Co-authored-by: Yixuan Zhai <6344553+randombet@users.noreply.github.com> Co-authored-by: ManuelPeixotoCegid <mapeixoto@cegid.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: lif <1835304752@qq.com> Co-authored-by: Pastukhov Nikita <diementros@yandex.ru> Co-authored-by: yashdeepkumar <54739723+yashdeepkumar@users.noreply.github.com>
Why are these changes needed?
Currently, AG2's
run()andrun_group_chat()methods execute the workflow in background threads, meaning that they run independently of when events are consumed. This is somewhat deceptive, as it feels like you're stepping through the orchestration but it is running separately and could be completed by the time you even move to the second event.I'm introducing the ability to step through events and hold execution at those events with new iterator methods,
run_iteron ConversableAgent, andrun_group_chat_iterfor group chats. This stops the background execution, essentially it is waiting for you to acknowledge the step before it continues to process.This utilises the current events framework, with a step controller helping to stop execution on the events.
The following events always trigger a step of the
iter_onfilter on the new methods:InputRequestEventErrorEventRunCompletionEventNone)iter_on
The
iter_onparameter allows you to specify which events you want to stop on. This is useful if you don't need to stop on all events.Using custom events
I've added a notebook that provides a guide on creating your own events that you can then step on.
Example of stepping through
Related issue number
N/A
Checks