Skip to content

refactor(ag2): migrate python sample to AG2 v1.0.0 - #690

Merged
yarolegovich merged 5 commits into
a2aproject:mainfrom
vvlrff:refactor/ag2-sample-ag2-v1
Nov 13, 2026
Merged

yarolegovich merged 5 commits into
a2aproject:mainfrom
vvlrff:refactor/ag2-sample-ag2-v1

Conversation

@vvlrff

@vvlrff vvlrff commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description

AG2 v1.0.0 is a full API rewrite — the package moved from autogen to ag2
and none of the APIs this sample used still exist, so it did not run at all.
This migrates it.

API changes

before (autogen, 0.10) after (ag2, 1.0)
ConversableAgent / LLMConfig Agent / OpenAIResponsesConfig
system_message= prompt=
@agent.register_for_llm(...) @tool(...) passed via tools=
A2aAgentServer(agent).build() A2AServer(agent).build_jsonrpc(url=, card=)
A2aRemoteAgent(url=) Agent(config=A2AConfig(card_url=))
a_initiate_chat + is_termination_msg as_tool() + ask()

initiate_chat and termination predicates are gone in v1. The idiomatic
replacement: the remote reviewer is a plain Agent configured with
A2AConfig, and as_tool() turns it into a tool of the local codegen agent,
so the delegation still crosses A2A. The "stop when the reviewer reports no
issues" condition moves from is_termination_msg into the prompt.

Other changes

  • Dependencies: added a2a-sdk[http-server,grpc]. ag2.a2a.server
    imports its grpc transport unconditionally, so JSON-RPC-only usage still
    needs grpcio — without it the server fails to import.
  • Workspace lock: bumped google-genai 1.31.0 -> 1.75.0 in
    samples/python/uv.lock. import ag2 crashed with
    AttributeError: module 'google.genai.types' has no attribute 'ImageConfig'
    because ag2 guards its optional gemini import with except ImportError
    only. See the caveat below.
  • Bug fix: the mypy tool never called flush() on its tempfile, so mypy
    checked an empty file and always reported success.
  • Updated the model to gpt-5.6-luna and refreshed the README.

Verification

Ran the reviewer server and both clients end to end against a stub
OpenAI-compatible endpoint: codegen agent -> review_code tool -> A2A
JSON-RPC -> reviewer agent -> real mypy -> back to the client. The agent card
is served at /.well-known/agent-card.json. ruff check reports the same
findings as before this PR, no new ones.

Not verified:

  • The live request/response path. The stub implements /chat/completions,
    while OpenAIResponsesConfig targets the Responses API, so that leg needs
    a run with a real key.
  • Other samples after the google-genai bump. The new version satisfies
    every other member's constraint (>=1.9, >=1.27), but I only confirmed
    the ag2 sample works — the lock is shared across the whole workspace, so
    this is worth a look during review.

Relates to #462 (moves this sample onto a2a-sdk 1.x).
Does not address #454 — the sample still defaults to OpenAI.

vvlrff and others added 5 commits August 18, 2026 10:26
AG2 v1.0.0 is a full API rewrite, so the sample no longer ran at all.

- switch from the `autogen` package to `ag2`
- `ConversableAgent`/`LLMConfig` -> `Agent`/`OpenAIResponsesConfig`
- `register_for_llm` -> the `@tool` decorator passed via `tools=`
- `A2aAgentServer(...).build()` -> `A2AServer(...).build_jsonrpc(url=, card=)`
- `A2aRemoteAgent` -> `Agent(config=A2AConfig(card_url=))`
- replace `a_initiate_chat` + `is_termination_msg`, both gone in v1, with
  `as_tool()` delegation; the termination condition moves into the prompt
- add `a2a-sdk[http-server,grpc]`: `ag2.a2a.server` imports the grpc
  transport unconditionally, so JSON-RPC-only usage still needs grpcio
- bump google-genai in samples/python/uv.lock: `import ag2` crashed on
  1.31.0 because ag2 guards its optional gemini import with `except
  ImportError` only
- fix the mypy tool never flushing its tempfile, so it checked an empty file
- update the model to gpt-5.6-luna and refresh the README
…ivity

Update AG2 Python samples by changing the host binding from 0.0.0.0 to 127.0.0.1
to improve local security and adding docstrings to main functions for
better documentation.
AG2 1.x requires a2a-sdk 1.x while the rest of the samples/python workspace
is on 0.3.x, so drop ag2 from the workspace and give it its own lock.
@yarolegovich
yarolegovich merged commit 1d7b7be into a2aproject:main Nov 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants