Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit Β·
856a2e4
1
Parent(s): 5fe810b
readme upt
Browse files- agent/README.md +16 -119
agent/README.md
CHANGED
|
@@ -1,127 +1,24 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
##
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
β βββ base.py # Base classes and interfaces
|
| 12 |
-
β βββ planner.py # Task planning and decomposition
|
| 13 |
-
β βββ executor.py # Task execution engine
|
| 14 |
-
β
|
| 15 |
-
βββ tools/ # Agent tools and actions
|
| 16 |
-
β βββ base.py # Tool base class and registry
|
| 17 |
-
β βββ search/ # Search tools (models, datasets, papers)
|
| 18 |
-
β βββ generation/ # Generation tools (content, code, data)
|
| 19 |
-
β βββ analysis/ # Analysis and evaluation tools
|
| 20 |
-
β βββ dataset_ops/ # Dataset operations
|
| 21 |
-
β
|
| 22 |
-
βββ prompts/ # Prompt templates
|
| 23 |
-
β βββ system/ # System prompts
|
| 24 |
-
β βββ task/ # Task-specific prompts
|
| 25 |
-
β βββ few_shot/ # Few-shot examples
|
| 26 |
-
β
|
| 27 |
-
βββ memory/ # Memory systems
|
| 28 |
-
β βββ short_term/ # Conversational memory
|
| 29 |
-
β βββ long_term/ # Persistent knowledge
|
| 30 |
-
β
|
| 31 |
-
βββ config/ # Configuration
|
| 32 |
-
β βββ settings.py # Settings management
|
| 33 |
-
β βββ default_config.json
|
| 34 |
-
β
|
| 35 |
-
βββ utils/ # Utilities
|
| 36 |
-
β βββ logging.py # Logging setup
|
| 37 |
-
β βββ retry.py # Retry logic
|
| 38 |
-
β
|
| 39 |
-
βββ tests/ # Test suite
|
| 40 |
-
βββ unit/ # Unit tests
|
| 41 |
-
βββ integration/ # Integration tests
|
| 42 |
-
```
|
| 43 |
-
|
| 44 |
-
## Key Components
|
| 45 |
-
|
| 46 |
-
### Core
|
| 47 |
-
- **Agent**: Main orchestrator that coordinates planning, execution, and reflection
|
| 48 |
-
- **Planner**: Breaks down complex tasks into actionable steps
|
| 49 |
-
- **Executor**: Executes individual steps using available tools
|
| 50 |
-
|
| 51 |
-
### Tools
|
| 52 |
-
- Modular tool system with base class and registry
|
| 53 |
-
- Tools organized by category (search, generation, analysis, dataset ops)
|
| 54 |
-
- Each tool can be registered and used by the agent
|
| 55 |
-
|
| 56 |
-
### Memory
|
| 57 |
-
- **Short-term**: Manages conversation context and current task state
|
| 58 |
-
- **Long-term**: Persistent storage for learned knowledge and past interactions
|
| 59 |
|
| 60 |
-
### Prompts
|
| 61 |
-
- Template-based prompt management
|
| 62 |
-
- System prompts for agent behavior
|
| 63 |
-
- Task-specific prompts for different operations
|
| 64 |
-
- Few-shot examples for learning
|
| 65 |
-
|
| 66 |
-
## Usage
|
| 67 |
-
|
| 68 |
-
```python
|
| 69 |
-
from agent import Agent
|
| 70 |
-
from agent.config import load_config
|
| 71 |
-
|
| 72 |
-
# Load configuration
|
| 73 |
-
config = load_config()
|
| 74 |
-
|
| 75 |
-
# Create agent
|
| 76 |
-
agent = Agent(config=config.model_dump())
|
| 77 |
-
|
| 78 |
-
# Run a task
|
| 79 |
-
result = await agent.run("Find the top 5 text generation models")
|
| 80 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
### Adding a New Tool
|
| 85 |
-
|
| 86 |
-
1. Create a new file in the appropriate `tools/` subdirectory
|
| 87 |
-
2. Inherit from `BaseTool`
|
| 88 |
-
3. Implement `execute()` and `_get_parameters()`
|
| 89 |
-
4. Register the tool with the agent
|
| 90 |
-
|
| 91 |
-
```python
|
| 92 |
-
from agent.tools.base import BaseTool
|
| 93 |
-
|
| 94 |
-
class MyTool(BaseTool):
|
| 95 |
-
name = "my_tool"
|
| 96 |
-
description = "Does something useful"
|
| 97 |
-
|
| 98 |
-
async def execute(self, **kwargs):
|
| 99 |
-
# Implementation
|
| 100 |
-
pass
|
| 101 |
-
|
| 102 |
-
def _get_parameters(self):
|
| 103 |
-
return {
|
| 104 |
-
"type": "object",
|
| 105 |
-
"properties": {...}
|
| 106 |
-
}
|
| 107 |
-
```
|
| 108 |
-
|
| 109 |
-
### Running Tests
|
| 110 |
-
|
| 111 |
-
```bash
|
| 112 |
-
pytest agent/tests/
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
## Configuration
|
| 116 |
-
|
| 117 |
-
Configure the agent via `config/default_config.json` or by passing a config dict:
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
"temperature": 0.7,
|
| 123 |
-
"max_iterations": 10,
|
| 124 |
-
"reflection_enabled": True
|
| 125 |
-
}
|
| 126 |
-
agent = Agent(config=config)
|
| 127 |
```
|
|
|
|
| 1 |
+
# Agent
|
| 2 |
|
| 3 |
+
Async agent loop with LiteLLM.
|
| 4 |
|
| 5 |
+
## Architecture
|
| 6 |
|
| 7 |
+
**Queue-based async system:**
|
| 8 |
+
- Submissions in (user input) β Agent Loop β Events output for possible UI updates
|
| 9 |
+
- Session maintains state (context + tools) for possible future Context Engineering
|
| 10 |
+
- Handlers operations like (USER_INPUT, INTERRUPT, COMPACT, UNDO, SHUTDOWN) for possible UI control
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
```
|
| 13 |
+
core/
|
| 14 |
+
βββ agent_loop.py # submission_loop + Handlers
|
| 15 |
+
βββ session.py # Session, Event, OpType
|
| 16 |
+
βββ executor.py # ToolExecutor
|
| 17 |
|
| 18 |
+
context_manager/
|
| 19 |
+
βββ manager.py # Message history management
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
config.py # Config with model_name + tools
|
| 22 |
+
tools/ # Tool implementations (todo)
|
| 23 |
+
utils/ # Logging, etc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
```
|