Skip to content

docs: fix Python examples passing dict to session.send() instead of positional str + keyword args#1128

Open
Akhand-99 wants to merge 1 commit into
github:mainfrom
Akhand-99:fix/python-send-dict-docs
Open

docs: fix Python examples passing dict to session.send() instead of positional str + keyword args#1128
Akhand-99 wants to merge 1 commit into
github:mainfrom
Akhand-99:fix/python-send-dict-docs

Conversation

@Akhand-99
Copy link
Copy Markdown

Closes #1127

What does this change do?

Fixes broken Python code examples in two docs files where session.send() is called with a dict instead of the correct positional str and keyword arguments.

docs/auth/byok.md — 1 line changed:

- await session.send({"prompt": "What is 2+2?"})
+ await session.send("What is 2+2?")

docs/features/steering-and-queueing.md — 3 Python blocks, 8 lines changed:

- msg_id = await session.send({
-     "prompt": "Refactor the authentication module to use sessions",
- })
+ msg_id = await session.send("Refactor the authentication module to use sessions")
 
- await session.send({
-     "prompt": "Actually, use JWT tokens instead of sessions",
-     "mode": "immediate",
- })
+ await session.send(
+     "Actually, use JWT tokens instead of sessions",
+     mode="immediate",
+ )
 
# (same pattern repeated for the queueing and combining sections)

Why is this needed?

session.send() has this signature:

async def send(self, prompt: str, *, mode: Literal["enqueue", "immediate"] | None = None) -> str:

Python does not enforce type hints at runtime. When a dict is passed as prompt, two things silently break:

1. prompt bug (both files): The dict is forwarded verbatim as the prompt value in the JSON-RPC payload to the CLI binary:

{ "sessionId": "...", "prompt": { "prompt": "What is 2+2?" } }

The CLI receives prompt as a JSON object instead of a string and calls .asString() on it, throwing TypeError: t.asString is not a function. This surfaces as a session.error event — no Python exception is raised, making it extremely difficult to diagnose:

Received event: session.info
Received event: session.tools_updated
Received event: session.error
error_type='query'  message='t.asString is not a function'
Received event: session.idle

2. mode bug (steering-and-queueing.md only): The * in the signature makes mode a keyword-only argument. When mode is buried inside a dict, it is never actually passed to send() — the steering and queueing behaviour silently does nothing. The agent receives no delivery mode instruction at all.

Both issues are caused by the same issue in the docs: using a dict where the Python SDK expects positional and keyword arguments.

Notes for maintainers

  • All other language tabs (Node.js, Go, .NET, Java) use the correct calling convention and are unaffected.
  • The byok.md fix is a single line. In that example I kept the existing asyncio.Event / on_event handler pattern unchanged to keep the diff minimal. If you prefer to align it with the other language tabs by switching to send_and_wait("..."), I am happy to update.
  • A related improvement worth considering (out of scope for this PR): adding if not isinstance(prompt, str): raise TypeError(...) in session.py send() would surface this class of mistake immediately at the Python level rather than as a cryptic CLI error. Happy to follow up with a separate issue or PR if that would be useful.
@Akhand-99 Akhand-99 requested a review from a team as a code owner April 23, 2026 15:41
@Akhand-99
Copy link
Copy Markdown
Author

I kindly request a review of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant