Skip to content

Commit f286488

Browse files
authored
add claude files (#1157)
1 parent 694d2bf commit f286488

7 files changed

Lines changed: 248 additions & 5 deletions

File tree

CLAUDE.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Marvin - AI Engineering Toolkit
2+
3+
Marvin is a lightweight AI engineering toolkit for building natural language interfaces that are reliable, scalable, and easy to trust.
4+
5+
## Architecture & Design Philosophy
6+
7+
- **Aggressively minimal and elegant**: Keep implementations simple and focused
8+
- **Functional first**: Prefer functional approaches, use classes where justified
9+
- **Type-safe**: Full type annotations, modern Python syntax (3.10+)
10+
- **Private internals**: Keep implementation details "private" (e.g. `def _impl`)
11+
12+
## Key Components
13+
14+
- **Engine**: Core AI interaction layer
15+
- **Tasks**: Structured AI task definitions and execution
16+
- **Tools**: Extensible function calling capabilities
17+
- **Agents**: AI agents with tool access and memory
18+
- **Memory**: Persistent conversation and context storage
19+
- **Handlers**: Event processing and routing
20+
- **CLI**: Command-line interface for common operations
21+
22+
## Development Guidelines
23+
24+
### Type Hints
25+
- Use `X | Y` instead of `Union[X, Y]`
26+
- Use builtins like `list`, `dict` instead of `typing.List`, `typing.Dict`
27+
- Use `T | None` instead of `Optional`
28+
29+
### Dependencies & Running
30+
- Use `uv` for dependency management and script execution
31+
- Install deps: `uv sync` or `uv sync --extra foo`
32+
- Run scripts: `uv run some/script.py` or `uv run --with pandas script.py`
33+
- Testing: `uv run pytest` or `uv run pytest -n3` for parallel
34+
35+
### Finding Things
36+
- Use `rg` for searching, not grep
37+
- Use `ls` and `tree` for navigation
38+
- Check git context with `gh` and `git` commands
39+
- Think like a hacker with good intentions - search in site-packages when needed
40+
41+
### Linter Philosophy
42+
- Empirically understand by running code
43+
- Linter tells basic truths but may be orthogonal to goals
44+
- Don't obsess over upstream linter errors, use as clues when relevant

examples/slackbot/CLAUDE.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Marvin Slackbot
2+
3+
An intelligent Slack bot built with Marvin that provides AI-powered assistance in Slack channels.
4+
5+
## Architecture
6+
7+
- **`slack.py`**: Core Slack API integration and event handling
8+
- **`core.py`**: Bot logic and message processing pipeline
9+
- **`api.py`**: FastAPI web server for Slack webhooks
10+
- **`modules.py`**: Modular bot functionality and plugins
11+
- **`search.py`**: Search capabilities and knowledge retrieval
12+
- **`wrap.py`**: Message formatting and response wrapping
13+
- **`strings.py`**: String constants and templates
14+
- **`settings.py`**: Configuration management
15+
16+
## Key Features
17+
18+
- Event-driven message processing
19+
- Modular plugin system for extensibility
20+
- Context-aware conversations with memory
21+
- Search integration for knowledge lookup
22+
- FastAPI webhook endpoint for Slack events
23+
- Docker deployment ready
24+
25+
## Development Notes
26+
27+
- Bot runs as FastAPI server listening for Slack events
28+
- Uses Slack's Events API for real-time message processing
29+
- Maintains conversation context and memory across interactions
30+
- Modular design allows easy addition of new capabilities
31+
- Environment-based configuration via settings
32+
33+
## Running the Bot
34+
35+
```bash
36+
# Install dependencies
37+
uv sync
38+
39+
# Start the bot server
40+
uv run examples/slackbot/start.py
41+
42+
# Or with Docker
43+
docker build -f examples/slackbot/Dockerfile.slackbot -t marvin-slackbot .
44+
docker run marvin-slackbot
45+
```
46+
47+
## Configuration
48+
49+
Set up environment variables or `.env` file:
50+
- Slack bot token and signing secret
51+
- AI model configuration
52+
- Database settings for memory persistence

goose_horror_story.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/marvin/agents/CLAUDE.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Marvin Agents
2+
3+
AI agents with tool access, memory, and autonomous decision-making capabilities.
4+
5+
## Core Concepts
6+
7+
- **Agent**: Autonomous AI entity that can use tools and maintain memory
8+
- **Tool Integration**: Seamless function calling with type safety
9+
- **Memory Persistence**: Conversation history and context retention
10+
- **Decision Making**: Goal-oriented task execution
11+
12+
## Key Components
13+
14+
- Agent class with tool orchestration
15+
- Memory management for context persistence
16+
- Tool registration and execution framework
17+
- Event handling for agent actions
18+
19+
## Usage Patterns
20+
21+
```python
22+
from marvin import Agent
23+
24+
# Create agent with tools
25+
agent = Agent(tools=[my_tool_fn])
26+
27+
# Run autonomous task
28+
result = agent.run("Analyze the data and create a report")
29+
```
30+
31+
## Design Notes
32+
33+
- Agents are stateful and maintain conversation context
34+
- Tools are regular Python functions with type hints
35+
- Memory is automatically managed and persisted
36+
- Agents can chain tool calls to accomplish complex tasks

src/marvin/engine/CLAUDE.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Marvin Engine
2+
3+
Task orchestration and execution engine that coordinates actors, manages conversations, and handles tool calls.
4+
5+
## Core Components
6+
7+
- **`orchestrator.py`**: Main execution loop - manages task dependencies, actor turns, message flow, and MCP servers
8+
- **`streaming.py`**: Real-time event handling during agent execution
9+
- **`end_turn.py`**: Special tools that end agent turns (MarkTaskSuccessful, DelegateToActor, PostMessage, etc.)
10+
- **`events.py`**: Event types for tool calls, completions, errors
11+
- **`llm.py`**: Basic LLM message types
12+
13+
## Orchestrator Flow
14+
15+
1. **Task Collection**: Gathers ready tasks and dependencies via `get_all_tasks()`
16+
2. **Tool Assembly**: Collects regular tools + end-turn tools from tasks/actors
17+
3. **Memory Integration**: Auto-searches memories based on recent messages
18+
4. **System Prompt**: Builds context from actor, instructions, and assigned tasks
19+
5. **Agent Execution**: Runs pydantic-ai agent with streaming event handling
20+
6. **Turn Management**: Processes end-turn tools, updates task states
21+
22+
## Key Classes
23+
24+
- `Orchestrator`: Main coordinator with `run()` and `run_once()` methods
25+
- `SystemPrompt`: Jinja template combining actor, instructions, and tasks
26+
- `EndTurn` subclasses: Tools that mark tasks complete/failed/skipped or delegate
27+
28+
## Usage
29+
30+
```python
31+
from marvin.engine.orchestrator import Orchestrator
32+
33+
orchestrator = Orchestrator(tasks=[my_task], thread=thread)
34+
results = await orchestrator.run(max_turns=5)
35+
```

src/marvin/tasks/CLAUDE.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Marvin Tasks
2+
3+
Structured AI task definitions and execution framework for reliable, type-safe AI operations.
4+
5+
## Core Concepts
6+
7+
- **Task**: Declarative AI operation with clear inputs/outputs
8+
- **Type Safety**: Full Pydantic validation of task parameters and results
9+
- **Reliability**: Built-in retry logic and error handling
10+
- **Composability**: Tasks can be chained and combined
11+
12+
## Task Types
13+
14+
- **Classification**: Categorize inputs into predefined classes
15+
- **Extraction**: Pull structured data from unstructured text
16+
- **Generation**: Create content based on specifications
17+
- **Transformation**: Convert data from one format to another
18+
19+
## Usage Patterns
20+
21+
```python
22+
from marvin import task
23+
24+
@task
25+
def extract_contact_info(text: str) -> ContactInfo:
26+
"""Extract contact information from text"""
27+
...
28+
29+
# Task automatically handles AI interaction
30+
result = extract_contact_info("Call John at 555-1234")
31+
```
32+
33+
## Design Philosophy
34+
35+
- Tasks are pure functions with AI capabilities
36+
- Type hints drive behavior and validation
37+
- Docstrings provide context to the AI model
38+
- Results are guaranteed to match return type annotations

src/marvin/tools/CLAUDE.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Marvin Tools
2+
3+
Minimal tool infrastructure - most tools come from agents, tasks, memories, and MCP servers.
4+
5+
## What's Here
6+
7+
- **`thread.py`**: Single function `post_message_to_agents()` for inter-agent communication
8+
- **`interactive/cli.py`**: Interactive CLI tools for user input during agent execution
9+
10+
## Tool Sources
11+
12+
Tools are provided by:
13+
- **Agent.get_tools()**: Agent-specific functions
14+
- **Task.get_tools()**: Task-related functions
15+
- **Memory.get_tools()**: Memory search/retrieval functions
16+
- **MCP Servers**: External tools via Model Context Protocol
17+
18+
## Utilities (`utilities/tools.py`)
19+
20+
- **`update_fn()`**: Modify function name/docstring dynamically
21+
- **`wrap_tool_errors()`**: Convert exceptions to `ModelRetry` for pydantic-ai
22+
- **`ResultTool`**: Dataclass for result-type tools
23+
24+
## Tool Error Handling
25+
26+
```python
27+
# All tools get wrapped automatically
28+
@wrap_tool_errors
29+
def my_tool():
30+
# Any exception becomes ModelRetry
31+
raise ValueError("Tool failed")
32+
```
33+
34+
## MCP Integration
35+
36+
External tools via MCP servers are discovered and wrapped automatically:
37+
- Server tools converted to pydantic-ai format
38+
- Full async/sync support
39+
- Error handling via `_mcp_tool_wrapper()`
40+
41+
## Usage Pattern
42+
43+
Tools are regular Python functions - no special base classes required. Function signature + docstring = tool schema.

0 commit comments

Comments
 (0)