Skip to main content

Python SDK for the AgentField control plane

Project description

AgentField Python SDK

The AgentField SDK provides a production-ready Python interface for registering agents, executing workflows, and integrating with the AgentField control plane.

Installation

pip install agentfield

To work on the SDK locally:

git clone https://github.com/Agent-Field/agentfield.git
cd agentfield/sdk/python
python -m pip install -e .[dev]

Quick Start

from agentfield import Agent

agent = Agent(
    node_id="example-agent",
    agentfield_server="http://localhost:8080",
    dev_mode=True,
)

@agent.reasoner()
async def summarize(text: str) -> dict:
    result = await agent.ai(
        prompt=f"Summarize: {text}",
        response_model={"summary": "string", "tone": "string"},
    )
    return result

if __name__ == "__main__":
    agent.serve(port=8001)

AI Tool Calling

Let LLMs automatically discover and invoke agent capabilities across your system:

from agentfield import Agent, AIConfig, ToolCallConfig

app = Agent(
    node_id="orchestrator",
    agentfield_server="http://localhost:8080",
    ai_config=AIConfig(model="openai/gpt-4o-mini"),
)

@app.reasoner()
async def ask_with_tools(question: str) -> dict:
    # Auto-discover all tools and let the LLM use them
    result = await app.ai(
        system="You are a helpful assistant.",
        user=question,
        tools="discover",
    )
    return {"answer": str(result), "trace": result.trace}

# Filter by tags, limit turns, use lazy hydration
result = await app.ai(
    user="Get weather for Tokyo",
    tools=ToolCallConfig(
        tags=["weather"],
        schema_hydration="lazy",  # Reduces token usage for large catalogs
        max_turns=5,
        max_tool_calls=10,
    ),
)

Key features:

  • tools="discover" — Auto-discover all capabilities from the control plane
  • ToolCallConfig — Filter by tags, agent IDs, health status
  • Lazy hydration — Send only tool names/descriptions first, hydrate schemas on demand
  • Guardrailsmax_turns and max_tool_calls prevent runaway loops
  • Observabilityresult.trace tracks every tool call with latency

See examples/python_agent_nodes/tool_calling/ for a complete orchestrator + worker example.

Human-in-the-Loop Approvals

The Python SDK provides a first-class waiting state for pausing agent execution mid-reasoner and waiting for human approval:

from agentfield import Agent, ApprovalResult

app = Agent(node_id="reviewer", agentfield_server="http://localhost:8080")

@app.reasoner()
async def deploy(environment: str) -> dict:
    plan = await app.ai(f"Create deployment plan for {environment}")

    # Pause execution and wait for human approval
    result: ApprovalResult = await app.pause(
        approval_request_id="req-abc123",
        expires_in_hours=24,
        timeout=3600,
    )

    if result.approved:
        return {"status": "deploying", "plan": str(plan)}
    elif result.changes_requested:
        return {"status": "revising", "feedback": result.feedback}
    else:
        return {"status": result.decision}

Two API levels:

  • High-level: app.pause() blocks the reasoner until approval resolves, with automatic webhook registration
  • Low-level: client.request_approval(), client.get_approval_status(), client.wait_for_approval() for fine-grained control

See examples/python_agent_nodes/waiting_state/ for a complete working example.

See docs/DEVELOPMENT.md for instructions on wiring agents to the control plane.

Testing

pytest

To run coverage locally:

pytest --cov=agentfield --cov-report=term-missing

License

Distributed under the Apache 2.0 License. See the project root LICENSE for details.

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

agentfield-0.1.63.tar.gz (200.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentfield-0.1.63-py3-none-any.whl (225.0 kB view details)

Uploaded Python 3

File details

Details for the file agentfield-0.1.63.tar.gz.

File metadata

  • Download URL: agentfield-0.1.63.tar.gz
  • Upload date:
  • Size: 200.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for agentfield-0.1.63.tar.gz
Algorithm Hash digest
SHA256 54c33372ba08772193fccd7125f7199f5a32c246d9f4c53061d1760462887468
MD5 644da3b40704a39332e5d9b2e50b1a0b
BLAKE2b-256 db4f887051b3eee78a941379239f58273a8a7a30cfd2178c392095c8d76b29aa

See more details on using hashes here.

File details

Details for the file agentfield-0.1.63-py3-none-any.whl.

File metadata

  • Download URL: agentfield-0.1.63-py3-none-any.whl
  • Upload date:
  • Size: 225.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for agentfield-0.1.63-py3-none-any.whl
Algorithm Hash digest
SHA256 d03c113cbebb4fc5b75eb2f667fb77053153699238d49f79d4dea50bf3de82b1
MD5 cd1435922801ed6dbd7faa77dbbab077
BLAKE2b-256 a19d6324f6b20994b4d745ec72ca3d76b5305cc65aaea9b6d2afc5e97ed6b17b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page