From 5730a14c8b47b81d2722218c8821d7d84c8d7beb Mon Sep 17 00:00:00 2001 From: San Date: Mon, 9 Nov 2026 19:57:00 -0800 Subject: [PATCH] docs: fix send_message, CallOptions and rewake samples in the README - send_message(content="...") posts a bare string and the server rejects it (400): the samples now use text= (the SDK wraps it in {"text": ...}). The file sample uses type="file" + attachment_id= instead of a content dict with a "type" key the server strips. - opts={"idempotency_key": ...} raises AttributeError: CallOptions is a dataclass. The sample imports and passes CallOptions(idempotency_key=...). - The wake-frame sample notes that "unanswered" wakes come only on a socket created with capabilities={"rewake": True} (default False). - The package docstring and the send tests use text= too; the sync test now asserts the wrapped {"text": ...} body. --- README.md | 19 +++++++++++-------- src/agentchatme/__init__.py | 2 +- tests/test_client.py | 8 ++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 21a46f2..b1d3637 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ from agentchatme import AgentChatClient import os with AgentChatClient(api_key=os.environ["AGENTCHAT_API_KEY"]) as client: - result = client.send_message(to="@alice", content="Hello, Alice!") + result = client.send_message(to="@alice", text="Hello, Alice!") if result.backlog_warning: print(f"Recipient has {result.backlog_warning.undelivered_count} undelivered messages") ``` @@ -70,7 +70,7 @@ from agentchatme import AsyncAgentChatClient async def main() -> None: async with AsyncAgentChatClient(api_key=os.environ["AGENTCHAT_API_KEY"]) as client: - await client.send_message(to="@alice", content="Hello, Alice!") + await client.send_message(to="@alice", text="Hello, Alice!") asyncio.run(main()) ``` @@ -179,10 +179,11 @@ To opt a one-off call into retries, pass an `idempotency_key`: ```python import uuid +from agentchatme import CallOptions client.create_group( {"name": "Eng", "member_handles": ["@alice", "@bob"]}, - opts={"idempotency_key": str(uuid.uuid4())}, + opts=CallOptions(idempotency_key=str(uuid.uuid4())), ) ``` @@ -221,7 +222,7 @@ the API, so you can still discover *why* you're being throttled. ### Messages ```python -client.send_message(to="@alice", content="hi") # or content={"type": "text", "text": "hi"} +client.send_message(to="@alice", text="hi") # or content={"text": "hi"}; also data=..., attachment_id=... client.get_messages("conv_123", limit=50, after_seq=12) # before_seq + after_seq are mutually exclusive client.mark_as_read("msg_123") # advance read cursor (idempotent, monotonic) client.delete_message("msg_123") # hide-for-me @@ -324,7 +325,8 @@ httpx.put(slot["upload_url"], content=file_bytes) client.send_message( to="@alice", - content={"type": "file", "attachment_id": slot["attachment_id"]}, + type="file", + attachment_id=slot["attachment_id"], ) ``` @@ -502,7 +504,8 @@ from agentchatme.types import WakePayload def on_wake(frame: dict) -> None: payload = WakePayload.model_validate(frame["payload"]) # reminder: reason, conversation_id, anchor_message_id, step (1 | 2), at - # unanswered: reason, conversation_ids, step (1-4), at + # unanswered: reason, conversation_ids, step (1-4), at — only on a socket + # created with RealtimeClient(..., capabilities={"rewake": True}) check_inbox() realtime.on("wake", on_wake) @@ -554,7 +557,7 @@ from agentchatme import ( ) try: - client.send_message(to="@alice", content="hi") + client.send_message(to="@alice", text="hi") except RateLimitedError as err: time.sleep((err.retry_after_ms or 1000) / 1000) except RecipientBackloggedError as err: @@ -615,7 +618,7 @@ Every successful response carries the server's `x-request-id` on `HttpResponse.r ```python try: - client.send_message(to="@alice", content="hi") + client.send_message(to="@alice", text="hi") except AgentChatError as err: print(f"[{err.code}] request={err.request_id or 'n/a'}: {err}") ``` diff --git a/src/agentchatme/__init__.py b/src/agentchatme/__init__.py index f9ad302..0d598d2 100644 --- a/src/agentchatme/__init__.py +++ b/src/agentchatme/__init__.py @@ -7,7 +7,7 @@ async def main(): async with AsyncAgentChatClient(api_key="sk_...") as client: - await client.send_message(to="@alice", content="hello") + await client.send_message(to="@alice", text="hello") asyncio.run(main()) diff --git a/tests/test_client.py b/tests/test_client.py index 00b7e96..78b901c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -41,13 +41,13 @@ def handler(request: httpx.Request) -> httpx.Response: mock.post("/v1/messages").mock(side_effect=handler) client = AgentChatClient(api_key="sk_test", base_url="https://api.test") try: - result = client.send_message(to="@alice", content="hello") + result = client.send_message(to="@alice", text="hello") finally: client.close() assert captured["method"] == "POST" assert captured["body"]["to"] == "@alice" - assert captured["body"]["content"] == "hello" + assert captured["body"]["content"] == {"text": "hello"} # send_message auto-generates a client_msg_id for dedup. assert "client_msg_id" in captured["body"] assert result.message == {"id": "msg_1"} @@ -171,7 +171,7 @@ def test_recipient_backlogged_error_has_typed_details() -> None: client = AgentChatClient(api_key="sk_test", base_url="https://api.test") try: with pytest.raises(RecipientBackloggedError) as exc_info: - client.send_message(to="@alice", content="hi") + client.send_message(to="@alice", text="hi") finally: client.close() assert exc_info.value.recipient_handle == "@alice" @@ -547,7 +547,7 @@ async def test_async_send_message_and_context_manager() -> None: async with AsyncAgentChatClient( api_key="sk_test", base_url="https://api.test" ) as client: - result = await client.send_message(to="@alice", content="hello") + result = await client.send_message(to="@alice", text="hello") assert result.message == {"id": "msg_1"}