Skip to content

chore(number_guessing_game): python sample A2A 1.1.x update - #755

Open
Yarmoluk wants to merge 2 commits into
a2aproject:mainfrom
Yarmoluk:number-guessing-game-a2a-sdk-1x
Open

Yarmoluk wants to merge 2 commits into
a2aproject:mainfrom
Yarmoluk:number-guessing-game-a2a-sdk-1x

Conversation

@Yarmoluk

Copy link
Copy Markdown

Description

Moves samples/python/agents/number_guessing_game from a2a-sdk==0.3.0 to a2a-sdk[http-server]==1.1.0, following the 1.0 migration guide and the helloworld 1.1.x sample. The game, the file layout and the agents' output stay the same.

Changes, all inside the sample folder:

  • requirements.txt: a2a-sdk[http-server]==1.1.0. In 1.x, Starlette comes only with the http-server extra.
  • Agent cards: AgentCard / AgentSkill / AgentInterface constructors. supported_interfaces replaces url, and stateTransitionHistory is dropped because 1.x no longer has it.
  • Executors (Alice, Carol): a new conversation enqueues its Task first, as 1.x requires. For Alice this replaces updater.submit(). Also: Part(text=...), requires_input() (no final argument), and imports from a2a.helpers / a2a.server.*.
  • utils/server.py: DefaultRequestHandler(..., agent_card), and create_agent_card_routes + create_jsonrpc_routes in a Starlette app (replaces A2AStarletteApplication). The JSON-RPC path stays /a2a/v1.
  • utils/protocol_wrappers.py:
    • create_client() per call. In 1.x a ClientFactory keeps one httpx.AsyncClient, which fails with "Event loop is closed" because each sync wrapper runs its own asyncio.run.
    • SendMessageRequest and CancelTaskRequest.
    • The Task is read from the StreamResponse, since ClientTaskManager is gone.
  • agent_Bob.py: TaskState.TASK_STATE_INPUT_REQUIRED. States are printed with TaskState.Name(...) so the log stays readable (state=TASK_STATE_INPUT_REQUIRED).
  • README: SDK version in the coverage heading, SendMessage, and the task aggregation row.
  • ruff format (repo .ruff.toml) on the touched files. This accounts for most of the line count in Bob and Carol.

SDK version: a2a-sdk 1.1.0, the same exact pin as helloworld, multitenancy and sign_and_verify_agent_card.

How it was tested

Python 3.12, fresh venv:

cd samples/python/agents/number_guessing_game
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python agent_Alice.py &   # port 8001
python agent_Carol.py &   # port 8003
python agent_Bob.py       # guesses typed in; scripted by bisection for the transcripts

The game played to the end on 1.1.0. Last lines of Bob's output:

Alice says: correct! attempts: 6
...
=== Carol's visualisation (sorted) ===
Guesses so far:
  1.  25 -> Go higher
  2.  31 -> Go higher
  3.  34 -> Go higher
  4.  35 -> correct! attempts: 6
  5.  37 -> Go lower
  6.  50 -> Go lower
============================

You won! Exiting…

The "Try again" / "Well done!" multi-turn exchange between Bob and Carol completed as on 0.3.0. In a second run, the 400-attempt limit was reached and Bob's CancelTask reached Carol ([Carol] Task … canceled on request of peer agent). The same scripted game was played on 0.3.0 before the change for comparison. The only difference in output is the state name (TaskState.input_required → TASK_STATE_INPUT_REQUIRED).

ruff format --check --config .ruff.toml samples/python/agents/number_guessing_game/ passes. ruff check reports nothing new: 47 findings remain, all of which were already on main (48 there). They are mostly docstring style, EN DASH characters and missing __init__.py (INP001) in files this PR does not otherwise need to touch.

Not tested: Alice's cancel path (nothing calls it), Windows, Python 3.10/3.11, and a 0.3 client against the new servers (v0.3 compat is not enabled).

AI assistance was used to prepare this change. The game was run end to end locally on the new pin.

Part of #462 🦕

🤖 Generated with Claude Code

https://claude.ai/code/session_015Nn19mXGNFoFZgk3SaYC7Y

Yarmoluk and others added 2 commits November 13, 2026 11:13
Moves the number_guessing_game sample from a2a-sdk 0.3.0 to 1.1.0.

- Pin a2a-sdk[http-server]==1.1.0 (Starlette now comes with the extra).
- Agent cards: AgentCard/AgentSkill/AgentInterface constructors,
  supported_interfaces instead of url; drop state_transition_history.
- Executors: enqueue the initial Task first (replaces Alice's submit()),
  Part(text=...), requires_input() without final, a2a.helpers imports.
- Server: DefaultRequestHandler with agent_card, routes from
  create_agent_card_routes/create_jsonrpc_routes in a Starlette app.
- Client: create_client per call (each sync wrapper runs its own event
  loop), SendMessageRequest/CancelTaskRequest, read the Task from the
  StreamResponse (ClientTaskManager is gone), TASK_STATE_* enum names.
- README: SDK version, SendMessage, task aggregation row.
- ruff format on the touched files.

Part of a2aproject#462

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Nn19mXGNFoFZgk3SaYC7Y
Clears the super-linter findings on the files changed by this pull
request (ruff 0.15.8 with .ruff.toml, markdownlint-cli 0.48.0). No
behaviour change; one printed character changes (see RUF001).

- MD060: README tables use the compact style (delimiter rows spaced, one padding run removed); cell text unchanged.
- INP001: agent_Alice/Bob/Carol.py start with `#!/usr/bin/env python3`, as the repo's standalone scripts do; an __init__.py would trigger N999 on the capitalised file names.
- D205: module docstrings start with their summary sentence (the bare file-name line is dropped); send_followup summary split from its description.
- D103: docstring for agent_Bob.main().
- RUF002: en dashes and a Unicode hyphen in docstrings replaced with "-".
- RUF001: Carol's "Received well done – completing task" now prints "-".
- ANN201: send_text_async/send_text/send_followup -> Task | Message, extract_text -> str, build_starlette_app -> Starlette.
- ANN001: agent_card: AgentCard | dict, executor: AgentExecutor (imported under TYPE_CHECKING for TC002).
- BLE001 (_print_guesses): `# noqa: BLE001`, as in adk_currency_agent and multitenancy.
- BLE001 + S110 (initial debug print): contextlib.suppress(Exception), as in birthday_planner_adk; same exceptions swallowed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Nn19mXGNFoFZgk3SaYC7Y

This branch has not been deployed

No deployments
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.

1 participant