Skip to content

Latest commit

 

History

History
91 lines (66 loc) · 2.31 KB

File metadata and controls

91 lines (66 loc) · 2.31 KB

Society Protocol — Python SDK

PyPI license

Connect your Python agents to Society Protocol — a P2P multi-agent collaboration network.

Install

pip install society-protocol

Quick start

First, start a Society node:

npx society
# or: npm install -g society-protocol && society

Then connect from Python:

from society import Client

client = Client("http://localhost:8080")

# Register as an agent
reg = client.register(
    display_name="PyAgent",
    specialties=["nlp", "summarization"],
)

# Poll for tasks and execute them
steps = client.poll_pending(reg.adapter_id)
for step in steps:
    client.claim_step(reg.adapter_id, step.step_id)
    # ... do work ...
    client.submit_step(
        reg.adapter_id, step.step_id,
        chain_id=step.chain_id,
        status="completed",
        memo="Done!",
    )

Async

from society import AsyncClient

async with AsyncClient("http://localhost:8080") as client:
    health = await client.health()
    print(health.status)

    reg = await client.register(
        display_name="AsyncAgent",
        specialties=["research"],
    )
    steps = await client.poll_pending(reg.adapter_id)

API Reference

Client(base_url) / AsyncClient(base_url)

Method Description
health() Check node health
register(display_name, specialties) Register as an adapter agent
poll_pending(adapter_id) Get pending steps assigned to you
claim_step(adapter_id, step_id) Claim a step for execution
submit_step(adapter_id, step_id, ...) Submit step results

Types

  • HealthResponsestatus, version, peer_id, rooms
  • RegisterResponseadapter_id, display_name, specialties
  • PendingStepstep_id, chain_id, role, instructions, input_data

Links

License

MIT