Loading...
Loading...
A minimal teaching framework for understanding AI Agent architecture with core loop, fake LLM interface, and skill discovery system
npx skill4agent add aradotso/ai-agent-skills ai-agent-deep-dive-teaching-frameworkSkill by ara.so — AI Agent Skills collection.
ai-agent-deep-dive# Clone the repository
git clone https://github.com/tvytlx/ai-agent-deep-dive.git
cd ai-agent-deep-dive
# Install dependencies
poetry install
# Verify installation
poetry run agt --helpsrc/agt/agent.pysrc/agt/cli.py# Run agent with a simple query
poetry run agt "hello world"
# List available skills
poetry run agt --skills-dir ./skills --list-skills
# Specify custom skills directory
poetry run agt --skills-dir /path/to/skills "your query"query--skills-dir./skills--list-skillsfrom agt.agent import Agent
# Initialize agent with default fake LLM
agent = Agent()
# Run agent with a query
response = agent.run("What can you help me with?")
print(response)from agt.agent import Agent
# The agent loop follows this pattern:
# 1. Receive user input
# 2. Send to LLM (currently fake)
# 3. Stream response back
# 4. Execute any triggered skills
agent = Agent(skills_dir="./skills")
result = agent.run("Calculate 2+2")from agt.agent import Agent
class RealLLM:
"""Replace the fake LLM with real API calls"""
def __init__(self, api_key=None):
self.api_key = api_key or os.getenv("OPENAI_API_KEY")
def stream_response(self, prompt: str):
"""Stream tokens from real LLM"""
# Implementation would call actual API
# and yield tokens as they arrive
pass
# Extend Agent class to use real LLM
class ProductionAgent(Agent):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.llm = RealLLM()# skills/calculator.py
def add(a: int, b: int) -> int:
"""Add two numbers together"""
return a + b
def multiply(a: int, b: int) -> int:
"""Multiply two numbers"""
return a * b
# Skills metadata (optional)
SKILL_METADATA = {
"name": "calculator",
"description": "Basic arithmetic operations",
"functions": ["add", "multiply"]
}from agt.agent import Agent
import os
# Initialize with environment configuration
agent = Agent(
skills_dir=os.getenv("AGENT_SKILLS_DIR", "./skills")
)
# Process multiple queries
queries = [
"Hello, what can you do?",
"Calculate something",
"List your capabilities"
]
for query in queries:
print(f"\nUser: {query}")
response = agent.run(query)
print(f"Agent: {response}")# Example .env file
AGENT_SKILLS_DIR=./skills
OPENAI_API_KEY=your-api-key-here # For when you replace fake LLM
LOG_LEVEL=INFOfrom agt.agent import Agent
agent = Agent(
skills_dir="./custom_skills", # Custom skills location
verbose=True, # Enable detailed logging
max_iterations=10 # Limit agent loop iterations
)ai-agent-deep-dive/
├── src/
│ └── agt/
│ ├── agent.py # Core agent implementation
│ ├── cli.py # CLI entry point
│ └── __init__.py
├── skills/ # Skill modules directory
├── docs/ # Teaching documentation
├── pyproject.toml # Poetry dependencies
└── README.mdfrom agt.agent import Agent
import os
# Agent automatically discovers skills in directory
agent = Agent(skills_dir="./skills")
# Skills are loaded and available during agent execution
response = agent.run("Use available skills to help me")from agt.agent import Agent
agent = Agent()
# The fake LLM demonstrates streaming pattern
# Real implementation would stream from API
def handle_stream(query: str):
for chunk in agent.stream_query(query):
print(chunk, end="", flush=True)
print() # Newline after stream completesfrom agt.agent import Agent
class CustomAgent(Agent):
"""Extended agent with custom behavior"""
def pre_process(self, query: str) -> str:
"""Custom preprocessing"""
return query.strip().lower()
def post_process(self, response: str) -> str:
"""Custom postprocessing"""
return response.upper()
def run(self, query: str) -> str:
query = self.pre_process(query)
response = super().run(query)
return self.post_process(response)ai-agent-deep-dive-v2.1.pdfai-agent-deep-dive-v2.pdf/docs# Verify skills directory exists and has valid Python modules
import os
skills_dir = "./skills"
if not os.path.exists(skills_dir):
os.makedirs(skills_dir)
# List skills to debug
from agt.cli import main
# Run: poetry run agt --list-skills# Ensure you're in the project directory
cd ai-agent-deep-dive
# Reinstall dependencies
poetry install
# Verify installation
poetry run python -c "from agt.agent import Agent; print('OK')"# Install poetry
curl -sSL https://install.python-poetry.org | python3 -
# Or via pip
pip install poetry
# Verify
poetry --versionimport os
from openai import OpenAI
class OpenAILLM:
def __init__(self):
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def stream_response(self, prompt: str):
stream = self.client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
yield chunk.choices[0].delta.content