Gotong Python SDK — connect Python agents to an Gotong Hub over WebSocket.
Project description
gotong (Python SDK)
Connect Python agents to an Gotong Hub over WebSocket.
The Hub is the TypeScript reference implementation; this SDK speaks the same wire protocol (docs/PROTOCOL.md) so Python agents register into the same registry, get scheduled by the same scheduler, and appear in the same transcript as TypeScript or in-process agents.
Install
# from-source (recommended at this stage — PyPI publish is descoped)
pip install -e python-sdk/
# from PyPI — NOT yet published, decision tracked in
# https://github.com/Emir-Aksoy/Gotong/blob/main/.github/RELEASE-CHECKLIST.md
# pip install gotong
Requires Python ≥ 3.10.
Usage
import asyncio
from gotong import AgentParticipant, connect
class WriterAgent(AgentParticipant):
def __init__(self) -> None:
super().__init__(id="writer-py", capabilities=["draft"])
async def handle_task(self, task: dict) -> dict:
topic = task["payload"].get("topic", "?")
return {"text": f"on {topic}: a sentence courtesy of Python."}
async def main() -> None:
session = await connect(
url="ws://127.0.0.1:4000",
agents=[WriterAgent()],
api_key="my-key", # optional
on_state_change=lambda s, info: print(f"[state] -> {s} {info or ''}"),
)
await session.wait_closed()
asyncio.run(main())
Subclass AgentParticipant, give it an id + capabilities, override handle_task. Both async def handle_task and plain def handle_task work — the SDK awaits whichever you wrote.
Adapters — bring your own agent framework
gotong.adapters wraps an external framework's object as an AgentParticipant, so the Hub routes Tasks to it like any other agent. The framework is a peer dependency — importing the adapter never pulls in langgraph / crewai; you install those yourself only for real graphs.
from langgraph.graph import StateGraph
from gotong import connect
from gotong.adapters import langgraph_participant
graph = build_graph().compile() # any compiled StateGraph
agent = langgraph_participant(
graph,
id="researcher-lg",
capabilities=["research"],
# map the Gotong task <-> the graph's state dict (defaults pass the
# payload straight through and return the whole final state)
to_state=lambda task: {"question": task["payload"]["question"]},
from_state=lambda state: {"answer": state["answer"]},
)
await connect(url="ws://127.0.0.1:4000", agents=[agent])
The graph is duck-typed (anything with .invoke(state)), .ainvoke is preferred when present, and a sync graph runs off the event loop so it can't stall the other agents on the connection.
A CrewAI crew wraps the same way — duck-typed on .kickoff(inputs), .kickoff_async preferred:
from crewai import Crew
from gotong.adapters import crewai_participant
crew = Crew(agents=[...], tasks=[...])
agent = crewai_participant(
crew,
id="market-research-crew",
capabilities=["market-research"],
to_inputs=lambda task: {"topic": task["payload"]["topic"]},
from_output=lambda out: {"report": out.raw}, # default: {"text": out.raw}
)
What the SDK does
- Opens a WebSocket to the Hub
- Sends
HELLOwith your declared agents and optionalapiKey - Awaits
WELCOME, raisesConnectionRejectedonREJECT - Dispatches
TASKframes to the right agent'shandle_task, sends backRESULT - Replies to
PINGwithPONG, forwardsCANCELtoon_task_cancelled - Auto-reconnects on transport failure with exponential backoff
- Cleans up on
close()(sendsGOODBYE, closes the socket)
What it doesn't do (yet)
- Publish/subscribe on channels (the Python agent is task-side only in v0.5)
- Streaming results
- Resume of in-flight tasks across reconnect (the Hub fails them as
remote_disconnect, same as the Node SDK)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gotong-1.1.0.tar.gz.
File metadata
- Download URL: gotong-1.1.0.tar.gz
- Upload date:
- Size: 34.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a86456f07d3df97a6385b48361c1c43e73a8adc9f56c51baf4421015680353b1
|
|
| MD5 |
38c074f67383a8671f6274fbca3deb67
|
|
| BLAKE2b-256 |
07bff46bf9060b98fca3d80ab3c3418a722344fa6c353b0a9d5741bc22b9fe2a
|
File details
Details for the file gotong-1.1.0-py3-none-any.whl.
File metadata
- Download URL: gotong-1.1.0-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81a4cd1e20835979c7d63937e993a4fc64b73fe9b50fe9b4247c5b9588c2e48c
|
|
| MD5 |
64a32d2d1f11978b44bda57bd5208dfc
|
|
| BLAKE2b-256 |
42fa155734fdd0a3675ba7102b8909363c85fbe944afe721a30bed781d46972a
|