Skip to main content

Naylence Agent SDK

Project description

Join our Discord

Naylence Agent SDK (Python)

The Naylence Agent SDK is the official toolkit for building agents and clients on the Naylence Agentic Fabric. It gives you a clean, typed, async-first API for composing tasks, streaming results, and wiring agents together—locally or across a distributed fabric.

If you're new to Naylence, start here. For lower‑level transport/fabric internals, see naylence‑runtime.


Highlights

  • Ergonomic agent model — subclass BaseAgent (one-shot) or BackgroundTaskAgent (long‑running/streaming) and focus on your logic.
  • Typed messages & tasks — Pydantic models for Task, Message, Artifact, and JSON‑RPC A2A operations.
  • Async all the way — non‑blocking lifecycle with easy scatter‑gather helpers (Agent.broadcast, Agent.run_many).
  • Remote proxies — call agents by address or capabilities via Agent.remote_* helpers.
  • Streaming & cancellation — subscribe to live status/artifacts; cancel in‑flight work.
  • FastAPI integration — drop‐in JSON‑RPC router (create_agent_router) and /agent.json metadata endpoint.
  • Security ready — works with runtime security profiles; strict‑overlay requires the naylence‑advanced‑security add‑on.

Install

pip install naylence-agent-sdk

Python 3.12+ is required.


Quickstart (minimal)

import asyncio
from typing import Any
from naylence.fame.core import FameFabric
from naylence.agent import Agent, BaseAgent

class EchoAgent(BaseAgent):
    async def run_task(self, payload: Any, id: Any) -> Any:
        return payload

async def main():
    async with FameFabric.create() as fabric:
        address = await fabric.serve(EchoAgent())
        echo = Agent.remote_by_address(address)
        print(await echo.run_task("Hello, world!", None))

asyncio.run(main())

For a gentle, runnable tour—from single‑process to distributed orchestration—use the Examples repo: https://github.com/naylence/naylence-examples-python.


Core concepts

Agents & tasks

  • Implement run_task(payload, id) for simple one‑shot work, or override start_task(...)/get_task_status(...) for background jobs.
  • Message.parts carries either text (TextPart) or structured data (DataPart).
  • Long‑running flows stream TaskStatusUpdateEvent and TaskArtifactUpdateEvent until terminal (COMPLETED/FAILED/CANCELED).

Remote proxies

  • Agent.remote_by_address("echo@fame.fabric") to call a known address.
  • Agent.remote_by_capabilities(["agent"]) to call by capability (fabric does resolution).

Streaming & cancel

  • subscribe_to_task_updates(...) yields status/artifacts live.
  • cancel_task(...) requests cooperative cancellation when supported by the agent.

RPC operations

  • A2A JSON‑RPC methods (tasks/send, .../get, .../cancel, etc.) are provided for task lifecycle.
  • Custom functions can be exposed via the RPC mixin in the underlying fabric (e.g., streaming operations).

FastAPI router

  • Use create_agent_router(agent) to expose a JSON‑RPC endpoint (default: /fame/v1/jsonrpc) and GET /agent.json to return an AgentCard.

Choosing an agent base class

  • BaseAgent — great for synchronous/short tasks; the default fallback packages your return value into a Task(COMPLETED).
  • BackgroundTaskAgent — best for long‑running/streaming work. You implement run_background_task(...); the base manages queues, TTLs, and end‑of‑stream.

Both base classes include sensible defaults (poll‑based streaming, simple auth pass‑through). You can override any part of the lifecycle.


Development workflow

  • Add your agents in a project with the SDK.
  • Use FameFabric.create() in tests or local scripts to host agents in‑process.
  • For distributed setups, operate a sentinel/fabric with naylence‑runtime (or your infra) and connect agents remotely.
  • Use the Examples repo (https://github.com/naylence/naylence-examples-python) to learn patterns like scatter‑gather, RPC streaming, cancellation, and security tiers.

API Documentation

To generate API documentation from source:

# Generate Markdown docs to docs/api/
poetry run docs-gen

# Or specify a custom output directory
poetry run docs-gen --out path/to/output

The generated docs are Markdown files compatible with Nextra and other documentation systems.


Security notes

The SDK runs on the Naylence fabric’s security profiles:

  • direct / gated / overlay modes work out‑of‑the‑box with the open‑source stack.
  • strict‑overlay (sealed overlay encryption + SPIFFE/X.509 identities) is available only with the naylence‑advanced‑security package.

See repo links below for the advanced add‑on and images that bundle it.


Links

Docker images:

  • OSS: naylence/agent-sdk-python
  • Advanced: naylence/agent-sdk-adv-python (includes naylence-advanced-security; BSL-licensed add-on)

License & support

  • License: Apache‑2.0 (SDK).
  • Issues: please use the appropriate GitHub repo (SDK, Runtime, Examples, Advanced Security).

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

naylence_agent_sdk-0.4.5.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

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

naylence_agent_sdk-0.4.5-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file naylence_agent_sdk-0.4.5.tar.gz.

File metadata

  • Download URL: naylence_agent_sdk-0.4.5.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for naylence_agent_sdk-0.4.5.tar.gz
Algorithm Hash digest
SHA256 087835e404b358667b871a963e6463af0538e8da4b3a9449fea2329c6fd650e2
MD5 57a1df4a48a5513d9d54c7a5f4efd651
BLAKE2b-256 88e3abdd5ace4b79c2b8304ae75581fc6aa17f337d937279787c80314e83f412

See more details on using hashes here.

Provenance

The following attestation bundles were made for naylence_agent_sdk-0.4.5.tar.gz:

Publisher: publish-to-pypi.yml on naylence/naylence-agent-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file naylence_agent_sdk-0.4.5-py3-none-any.whl.

File metadata

File hashes

Hashes for naylence_agent_sdk-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0d94a8d27d34593db7fac5af5dda5e4257ded33d032152c2b3b27b42accf87ac
MD5 ba4695b6fa057a45ea7ce58e8f3383d8
BLAKE2b-256 5c54cc36ffe11a37436d1dd1fa4ea2a6895c5987e40f9e6b5f758af21145033d

See more details on using hashes here.

Provenance

The following attestation bundles were made for naylence_agent_sdk-0.4.5-py3-none-any.whl:

Publisher: publish-to-pypi.yml on naylence/naylence-agent-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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