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.
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:
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:
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
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
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
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
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
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
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