Skip to content

Python SDK Internals

This section documents the internal layout of the zyndai-agent Python package. If you only want to install it, scaffold an agent, and run it, go to Python SDK instead.

Use this section when:

  • You're contributing to the SDK.
  • You're embedding parts of it in another framework (e.g., calling dns_registry directly without a full agent).
  • You're debugging a stack trace and want to know which module owns the failure.

Module map

zyndai_agent/
├── __init__.py                  # Public API re-exports
├── base.py                      # ZyndBase — shared identity, heartbeat, registration
├── agent.py                     # ZyndAIAgent — wraps an LLM framework
├── service.py                   # ZyndService — wraps a plain Python function

├── identity.py                  # AgentIdentity — legacy DID layer (still imported by some examples)
├── ed25519_identity.py          # New canonical identity — keypair gen, sign, verify, HD derivation

├── entity_card.py               # EntityCard model + signing helpers
├── entity_card_loader.py        # Reads / writes .well-known/agent.json

├── dns_registry.py              # AgentDNS HTTP client — register, search, resolve, heartbeat
├── search.py                    # Search wrapper with filters + result models

├── communication.py             # Webhook HTTP client (outbound)
├── webhook_communication.py     # Flask server (inbound)
├── message.py                   # AgentMessage envelope model
├── payload.py                   # Payload schemas + validation

├── payment.py                   # x402 client + server middleware

├── config_manager.py            # Reads / writes ~/.zynd/* configs
└── utils.py                     # Misc helpers — slug, time, ports

What each module owns

Core lifecycle

ModuleOwns
base.ZyndBaseThe shared lifecycle. Loads keypair → derives entity_id → writes Entity Card → registers on AgentDNS → starts heartbeat thread → starts webhook server. Both ZyndAIAgent and ZyndService extend this.
agent.ZyndAIAgentAdds LLM framework integration. Accepts a LangChain / LangGraph / CrewAI / PydanticAI executor and wires it into the webhook handler.
service.ZyndServiceAdds the set_handler(fn) method for plain-Python services.

Identity

ModuleOwns
ed25519_identityCanonical identity layer. Functions: generate_keypair, save_keypair, load_keypair, derive_keypair, sign, verify. The derive_keypair(developer_seed, index) function is what produces HD child keys for entity registration.
identity.AgentIdentityLegacy DID-flavored layer kept for backward compatibility. New code should use ed25519_identity directly.

Entity Card

ModuleOwns
entity_card.EntityCardPydantic model for the live Agent Card published at /.well-known/agent.json. Fields: entity_id, name, capabilities, endpoints, pricing, input_schema, output_schema, signed_at, signature.
entity_card_loaderReads the developer's framework code, infers capabilities + schemas, builds an EntityCard, signs it with the entity keypair, writes to .well-known/agent.json on every start. Re-run on each start() so updates propagate without manual intervention.

Registry client

ModuleOwns
dns_registryThe AgentDNS HTTP client. One method per endpoint family: register_entity, update_entity, deregister_entity, get_entity, search, resolve_fqan, claim_handle, bind_name, plus the heartbeat WebSocket loop. Used by ZyndBase and exported for direct use.
searchPythonic wrapper on top of dns_registry.search() — typed filter args, result paging, optional Agent Card enrichment.

Communication

ModuleOwns
webhook_communicationFlask app with three routes: POST /webhook (async, returns 202), POST /webhook/sync (blocks for response), GET /.well-known/agent.json (serves the Entity Card). Optional ngrok auto-tunnel via pyngrok when [ngrok] extra is installed.
communicationOutbound HTTP client. Wraps requests + the x402 payment middleware. Used by ZyndAIAgent when one agent calls another.
message.AgentMessageEnvelope shape: id, from, to, payload, signature, timestamp. Signed by the sender, verified by the receiver against the registry's published public key.
payloadPayload validation. JSON Schema for input / output, version negotiation, error shapes.

Payment

ModuleOwns
paymentx402 implementation. Two halves: a Flask middleware that returns 402 Payment Required with a Base Sepolia USDC quote when the entity is paid, and a client that intercepts 402, settles on-chain, and retries with the X-PAYMENT header. Uses eth-account + x402 library.

Config

ModuleOwns
config_managerReads / writes ~/.zynd/developer.json, ~/.zynd/personas/*.json, and other state. Single source of truth for paths so the SDK and the CLI agree on layout.

Pages in this section

See also

Released under the MIT License.