Boilerplate Code Samples

These Python templates are built to demonstrate key single and multi-agent concepts from first principles. They use simulation and clean architecture to illustrate code structures without needing API keys or complex setups.

🔑

Gemini API Key Configuration (Production SDK)

Learn how and where to populate your API key to run production examples locally.

A

Method A: Set Environment Variable (Recommended)

All Production SDK examples are pre-configured to securely read your API key from the environment. Open your terminal and run:

export GEMINI_API_KEY="your_api_key_here"
B

Method B: Hardcode in Script (Local Dev Only)

Alternatively, you can open the python script and directly pass your API key to the client initialization block:

# Find client initialization in the script:
- api_key = os.environ.get("GEMINI_API_KEY") Remove
+ api_key = "AIzaSyYourGeminiAPIKeyHere" Add Key
client = genai.Client(api_key=api_key)
Example 01 01_react_loop.py

ReAct (Reason + Action) Loop

A low-level implementation of the classic ReAct agent loop. Illustrates how to format model prompts with strict Thought/Action/Observation tags, parse structured output instructions, execute mocked tool calls (like search), and feed results back into context.

Demonstrated Concepts:

  • ReAct logic framework (Thought → Action → Observation)
  • Regex parsing of model-produced tool calls
  • Dynamic history buffering and token thresholding
python examples/01_react_loop.py
Download
Example 02 02_mcp_server.py

Model Context Protocol Server

A stdio-based implementation of a Model Context Protocol (MCP) server. Standardizes how models interact with external data and tools, registering system commands, reading secure environment variables, and returning structured weather results.

Demonstrated Concepts:

  • Standardized MCP tools, prompts, and resources
  • JSON-RPC message processing over stdio channels
  • Safe integration configurations for Desktop Clients
python examples/02_mcp_server.py
Download
Example 03 03_crewai_collaboration.py

CrewAI Collaboration Workflow

Simulates how multiple specialized agents collaborate sequentially in a Crew. Defines a "Senior Technology Researcher" and a "Lead Technical Writer" who pipe context sequentially to draft a technical briefing.

Demonstrated Concepts:

  • Role, Backstory, and Goal configuration for personas
  • Sequential task pipelines passing outputs to inputs
  • Structured crew coordination and kickoff loops
python examples/03_crewai_collaboration.py
Download
Example 04 04_langgraph_workflow.py

LangGraph Stateful Cyclic Network

A blackboard state design pattern. Simulates a cyclic Writer-Critic graph where nodes are functions modifying a central shared State object, and a router decides to loops back or terminate based on the critique.

Demonstrated Concepts:

  • Shared Blackboard State objects for workflow data
  • Graph Nodes (processing steps) and linear/conditional Edges
  • Cyclic state-based routing and auto-termination limits
python examples/04_langgraph_workflow.py
Download
Example 05 05_autogen_chat.py

Microsoft AutoGen Conversational Session

A multi-agent conversational setup featuring an `AssistantAgent` (coder) and a `UserProxyAgent` (code executor). Demonstrates automated message-passing loops where the coder drafts a division function, the proxy reports a division-by-zero crash, and the coder outputs a fixed script which terminates successfully.

Demonstrated Concepts:

  • Conversational message-passing agent loops
  • Autonomous UserProxy code execution simulation
  • Custom criteria matching and TERMINATE handshakes
python examples/05_autogen_chat.py
Download
Example 06 06_self_reflection.py

Self-Correction Coding Agent

An autonomous program synthesis agent. Illustrates how an agent drafts Python code, attempts execution, catches compiler/runtime exceptions (tracebacks), and feeds the error details back into the LLM context to self-correct its bugs.

Demonstrated Concepts:

  • Dynamic program synthesis and local namespaces (`exec()`)
  • Exception catching and traceback formatting buffers
  • Iterative agent self-correction based on runtime validation feedback
python examples/06_self_reflection.py
Download
Example 07 07_agent2agent_protocol.py

Agent-to-Agent Protocol Handshake

An inter-agent task delegation and verification simulator. Illustrates how a supervisor agent handshakes cryptographically, verifies auth tokens, sends structured JSON payloads to specialized peer agents, and parses returned outcomes.

Demonstrated Concepts:

  • Cryptographic challenge and API key handshaking
  • Structured message payloads over peer connection models
  • Task verification and error delegation routing nodes
python examples/07_agent2agent_protocol.py
Download