Examples
This section links to example projects and code snippets in the repository.
Start with the Jupyter Notebooks in examples/notebooks/basic_example! They provide the easiest and best interactive introduction to running the Registry and Agents.
Jupyter Notebooks (Recommended)
The best way to get started is by running the interactive notebooks in examples/notebooks/basic_example. These notebooks teach you the core concepts of Protolink through a complete multi-agent system:
🎯 What You'll Learn
- Registry Setup: How to run a central discovery service for agents
- Agent Creation: Building agents with tools and task handling
- Agent Communication: How agents discover and communicate with each other
- Transport Configuration: Using HTTP transport for agent-to-agent messaging
- Tool Integration: Adding native tools to agents using decorators
📚 Notebook Sequence
Run these notebooks in order to build a complete weather monitoring system:
1. registry.ipynb - Start the Registry
- Sets up the central discovery service on
localhost:9010 - Exposes REST API endpoints for agent registration and discovery
- Provides a web interface at
/statusto view registered agents
2. weather_agent.ipynb - Create a Data Provider
- Builds an agent that provides mock weather data
- Demonstrates tool creation with the
@tooldecorator - Shows agent registration and task handling patterns
- Runs on
localhost:8010
3. alert_agent.ipynb - Create a Consumer Agent
- Builds an agent that processes weather data and sends alerts
- Demonstrates agent-to-agent communication via the registry
- Shows different transport configuration patterns
- Runs on
localhost:8020
🏗️ System Architecture
┌─────────────────┐ HTTP REST API ┌─────────────────┐
│ Registry │◄──────────────────►│ Alert Agent │
│ (localhost: │ │ (localhost: │
│ 9010) │ │ 8020) │
└─────────────────┘ └─────────────────┘
▲ ▲
│ │
│ HTTP REST API │ HTTP REST API
│ │
┌─────────────────┐ ┌─────────────────┐
│ Weather Agent │◄──────────────────►│ Alert Agent │
│ (localhost: │ │ │
│ 8010) │ │ │
└─────────────────┘ └─────────────────┘
🚀 Quick Start
- Start the Registry (run
registry.ipynbfirst) - Start the Weather Agent (run
weather_agent.ipynb) - Start the Alert Agent (run
alert_agent.ipynb) - Test the System: Visit
http://localhost:9010/statusto see all registered agents
💡 Key Concepts Demonstrated
- Transport Flexibility: Use transport strings (
"http") orHTTPTransportinstances - Registry Patterns: Pass registry as URL string or
Registryobject - Tool Creation: Native tools with automatic schema inference
- Task Handling: Implement
handle_taskfor processing incoming tasks - Agent Discovery: Find and communicate with other agents via the registry
Example Scripts
The repository includes several standalone example scripts that demonstrate specific Protolink capabilities:
Retrieval-augmented Agent
rag_agent.pybuilds a dependency-free in-memory knowledge base from twoDocumentvalues and attaches it to an Agent in automatic retrieval mode. ItsMockLLMselects the generatedsearch_handbooktool, reads the actual retrieved passage, and returns a citation-bearing answer through the normal inference loop.
python examples/rag_agent.py
The example opens no port and needs no API key, model server, vector-database
service, or network access. Read the
Retrieval-Augmented Generation guide for persistent SQLite
knowledge, existing Chroma/Pinecone/Qdrant indexes, custom retrievers,
deterministic Agent.ask(), filters, index lifecycle, and citation metadata.
Built-in web search
builtin_web_search.pyregistersweb_search()on a runtime Agent with an explicitnetwork.readpolicy. It defaults to English Wikipedia's documented keyless search API and accepts--engine,--freshness, and--max-resultsoptions. DuckDuckGo remains an explicit best-effort HTML option; select Brave after exportingBRAVE_SEARCH_API_KEY.
python examples/builtin_web_search.py "What is the capital of Greece?"
export BRAVE_SEARCH_API_KEY="your-key"
python examples/builtin_web_search.py "Python structured concurrency" --engine brave
python examples/builtin_web_search.py "Python structured concurrency" --engine duckduckgo
Run it without a query to inspect the CLI without making a network request.
A2A core and A2A 1.0 boundary
provider_free_mesh.pyruns a deterministic three-agent mesh with no provider, API key, registry, or network port. It demonstrates the A2A-derivedAgentCard,Task, andMessagemodel through the in-process runtime transport.a2a_tck_agent.pyis the provider-free HTTP fixture for the official A2A 1.0 TCK. It explicitly usesAgent(..., a2a=True); ordinary HTTP agents remain native-only by default. It is a compatibility test target, not a substitute for a published passing TCK result; follow the pinned instructions in A2A Core and 1.0 Compatibility.
Run regression diffing
run_regression_diff.pycreates provider-free baseline and candidate reports with different known runtime IDs, timestamps, sequence counters, and bounded latency, proves that schema-aware normalization plus an explicit tolerance remove that noise, and then detects a real final-output change withdiff_run_reports()andassert_run_matches(). Real candidate runs must be executed and recorded separately.
🧩 Protolink 0.6.3 runtime-control examples
The 0.6.3 examples are small, provider-free scripts intended for application integrators:
v063_context_budget.pyshowsContextManifest,LLMModelProfile, and enforcedRunBudgetbehavior before a model call.v063_history_compaction.pyshows localrecent,tokens, and isolatedsummarycompaction plus remoteAgentClient.compact_history()over the request-spec endpoint.v063_state_control.pyshows client/server statedescribe,compact, andresetrequests for one persistent conversation session.v063_run_reports.pyshowsRunRecorder,RunReport,RunReplay, golden-run assertions, and redaction.v063_protoagent_policy_mesh.pysketches the ProtoAgent Explorer/Coder/Architect structure abstractly. The prompts are intentionally tiny; the example focuses on tool capabilities,CapabilityPolicy, diff-previewaction_builders, and approval-gated workspace writes.
Production case study: ProtoAgent
ProtoAgent is a full local-first coding assistant built on ProtoLink. Read the case study to see how the runtime engine powers its Architect, Explorer, and Coder agent deck, approval-gated diffs, completion validation, Context Loom evidence, cancellation, history control, and run reports.
Flagship experiment: AI Courtroom
The AI Courtroom is a replayable multi-agent experiment built around a fictional autonomous-vehicle liability case. It compares one generalist, five independent specialists, a foreperson-star topology, and a direct agent-selected mesh while keeping public evidence and observable decision contracts controlled. Read the example page to see how jurors author direct ProtoLink messages, how one communication topology produces a different deterministic verdict, and how every run automatically generates standalone interactive HTML reports for replay and comparison.
For a model-versus-model experiment, see the
ai_courtroom_benchmark
example. It runs two advocates on opposite sides of a portable JSON case,
swaps their roles, keeps the judge and independent jury fixed, and generates a
standalone replay report with opinion trajectories, citations, vote flips, and
fairness checks.
🛠️ devtools_dashboard.py
Purpose: Local devtools, run replay, registry snapshot, and dashboard
- Uses
create_llm("mock"), so it runs without provider credentials - Creates several agents and registers their cards in an in-process registry
- Runs a small task loop and records each streamed run with
RunRecorder - Saves durable task snapshots and
RunReportrecords toSQLiteRunStore - Renders static dashboard HTML using
DevtoolsHtmlRenderer, including the disabled Studio preview - Prints follow-up commands for
protolink run list,protolink run replay, andprotolink dashboard - Supports
--serve-liveto start provider-free HTTP agents, an HTTP registry, and the dashboard so ping/chat actions can be clicked - The dashboard also contains registry health, selected-agent detail, run replay, and chat panels
📝 basic_agent.py
Purpose: Minimal agent setup focused on core concepts
- Demonstrates simplified agent creation using dictionary-based
AgentCard - Shows how to add native tools using the
@agent.tooldecorator with automatic schema inference - Demonstrates direct agent invocation using convenience methods:
invoke()andsync.invoke() - Includes optional LLM integration for reasoning and inference
- Uses
runtimetransport for in-memory execution (no network dependencies)
🧠 agent_memory.py
Purpose: Conversation memory and persistence across tasks
- Demonstrates the difference between stateless agents (
state=None) and persistent agents (state=["conversation"]) - Shows how
sync.invoke()handles session history automatically using a defaultsession_id - Demonstrates history persistence across sequential calls to the same agent instance
- Useful for building conversational bots and multi-turn interaction assistants
🌐 http_agents.py
Purpose: HTTP transport and agent-to-agent communication
- Demonstrates two agents communicating over HTTP
- Tests client functions:
get_agent_card,send_message_to,call_agent - Shows how to set up multiple agents on different ports
- Includes comprehensive error handling and cleanup
🔒 authentication.py
Purpose: Authentication, credentials propagation, and security verification
- Demonstrates API key, Basic, and signed Bearer JWT authentication providers
- Covers server-side route authentication (returning
401 Unauthorizedfor failed requests) - Covers client-side lazy authentication (automatic signature/credential injection on outgoing requests)
- Verifies both HTTP (Starlette and FastAPI backends) and WebSocket handshake verification
- Demonstrates success and failure scenarios for both transports
🤖 LLM notebooks
Purpose: LLM backend integration, inference loops, and delegation
- Demonstrates direct API LLM usage
- Shows
infer()with local tool calling - Shows
agent_calldelegation between agents - Complements the LLM Examples guide
📋 registry.py
Purpose: Registry discovery and autonomous agent behaviour
- Creates autonomous agents that discover peers and send tasks
- Demonstrates registry-based agent discovery
- Shows background task management and cleanup
- Multi-agent orchestration with automatic peer communication
⚡ runtime_agents.py
Purpose: In-memory agent communication interoperability
- Uses explicitly mapped URL
RuntimeTransportinstances for agent-to-agent communication without HTTP configuration - Demonstrates safe registry discovery enabling native message parsing safely inside isolated testing contexts
- Shows how to build reliable agent networks safely running within a single process retaining production semantics
- Useful for test pipelines scaling native workflow isolation
📡 streaming_agent.py
Purpose: Real-time streaming with progress updates
- Demonstrates streaming task handlers with progress events
- Shows artifact production and streaming
- Context management for multi-turn conversations
- Event-driven architecture with task status updates
🔌 websocket_basic_example.py
Purpose: WebSocket transport with streaming support
- Mirrors the basic notebook example but uses WebSocket transport
- Demonstrates both request/response and streaming task patterns
- Shows registry discovery over WebSockets
- Real-time progress updates via WebSocket events
grpc_agent.py
Purpose: gRPC transport request/response and streaming smoke test
- Starts a provider-free mock-LLM agent on a local
grpc://port - Fetches the agent card and sends a normal task through
AgentClient - Consumes task events through the gRPC streaming API
- Demonstrates the
transport="grpc"factory path without generated protobuf files
tls_agent.py
Purpose: Native TLS and mutual TLS through the high-level agent API
- Starts a provider-free mock agent on an
https://endpoint usingTLSConfig - Configures verified client trust without disabling hostname or certificate checks
- Supports
--require-client-certto demonstrate mutual TLS - Keeps certificate transport security separate from bearer/API-key authentication
🔄 structured_flows/
Purpose: Advanced flow orchestration patterns
- Demonstrates Graph flow for complex state machine topologies with cyclic loops
- Shows conditional branching and multi-step review workflows
- Examples include sequential processing, parallel execution, and dynamic routing
- Illustrates integration of multiple agents in structured flow patterns