- Add pytest-asyncio for handling async tests - Update test_llm.py with proper async test decorators - Add more assertions to LLM test |
||
|---|---|---|
| config | ||
| scripts | ||
| tasksamples | ||
| tests | ||
| __init__.py | ||
| .env.example | ||
| .gitignore | ||
| llm_client.py | ||
| llm_executor.py | ||
| pyproject.toml | ||
| README.md | ||
| requirements.txt | ||
| sample_task.py | ||
| task_executor.py | ||
| uv.lock | ||
Agent Task Executor
A flexible task execution framework that uses LLMs (Large Language Models).
Features
- Unique task identification
- State tracking and monitoring
- Checkpoint creation and rollback
- Resource usage monitoring
- Error handling and retry mechanism
- Execution path tracking
- Detailed status reporting
Project Structure
agent_task_executor/
├── config/ # Configuration files and utilities
│ ├── config_loader.py # Configuration loading utilities
│ ├── llm_config.yaml # LLM configuration settings
│ ├── secure_config.py # Secure configuration handling
│ └── secure.json # Secure configuration data (encrypted)
│
├── tasksamples/ # Sample task implementations
│ ├── __init__.py
│ └── text_analysis_task.py # Text analysis task implementation
│
├── tests/ # Test suite
│ ├── test_config.py # Configuration tests
│ └── test_llm.py # LLM functionality tests
│
├── scripts/ # Utility scripts
│
├── llm_client.py # LLM API client implementation
├── llm_executor.py # Core LLM execution logic
├── task_executor.py # Task execution framework
├── sample_task.py # Sample task demonstration
│
├── requirements.txt # Python dependencies
├── pyproject.toml # Project metadata and build configuration
└── .env.example # Example environment variables
Core Components
-
Task Execution Framework
task_executor.py: Core framework for task executionllm_executor.py: LLM-specific execution logicllm_client.py: Client for interacting with LLM APIs
-
Configuration Management
config/: Contains all configuration-related files- Secure configuration handling with encryption support
- LLM-specific configurations
-
Task Implementations
tasksamples/: Directory for task implementations- Text analysis task with Chinese text support
- Extensible for additional task types
-
Testing
- Comprehensive test suite for configuration and LLM functionality
- Unit tests for core components
Setup and Dependencies
The project uses Python with the following key dependencies:
- httpx: For making HTTP requests
- tenacity: For retry logic
- pyyaml: For configuration handling
- cryptography: For secure configuration
Environment Management
Package Management with UV
The project uses uv for fast Python package management:
# Install uv (if not already installed)
pip install uv
# Create virtual environment and install dependencies
uv venv
uv pip install -r requirements.txt
# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On Unix or MacOS:
source .venv/bin/activate
Lock File
The project uses uv.lock to ensure dependency consistency:
uv.lock: Contains exact versions of all dependencies- To update dependencies:
uv pip compile requirements.txt -o uv.lock - To sync with lock file:
uv pip sync uv.lock
Environment Variables
Required environment variables:
DEEPSEEK_API_KEY: API key for DeepSeek LLM serviceDEEPSEEK_API_BASE: Base URL for DeepSeek APICONFIG_PATH: Path to configuration directory (default: ./config)
Create a .env file in the project root:
DEEPSEEK_API_KEY=your_api_key_here
DEEPSEEK_API_BASE=https://api.deepseek.com/v1
CONFIG_PATH=./config
Configuration Files
-
llm_config.yaml: LLM service configurationllm: provider: deepseek model: deepseek-chat temperature: 0.7 max_tokens: 2000 -
secure.json: Encrypted configuration for sensitive data- Generated and managed by
secure_config.py - Uses encryption for storing API keys and secrets
- Generated and managed by
Usage
- Install dependencies:
uv pip install -r requirements.txt
- Run the sample task:
python sample_task.py
- Create your own task executor:
from task_executor import TaskExecutor
class CustomTaskExecutor(TaskExecutor):
def __init__(self):
super().__init__()
# Define your task steps
def validate_input(self, input_data):
# Implement input validation
pass
def execute_step(self, step_id, step_data):
# Implement step execution
pass
Task Execution Framework
Core Components
- Task Status Tracking
- Unique task ID
- Step-by-step progress monitoring
- Resource usage tracking
- Execution path recording
- Checkpointing System
- Automatic checkpoint creation every 5 steps
- Rollback capability
- State preservation
- Error Handling
- Maximum 3 retry attempts
- Timeout monitoring (300 seconds)
- Detailed error logging
- Status Reporting
- Real-time status updates
- Resource usage statistics
- Execution path history
- Error and warning logs
Status Output Format
{
"task_id": "unique_id",
"timestamp": "ISO-8601 timestamp",
"current_step": {
"id": "step_id",
"name": "step_name",
"status": "status",
"progress": "percentage"
},
"checkpoints": ["checkpoint_list"],
"resources": {
"used": "used_resources",
"available": "available_resources"
},
"execution_path": ["executed_steps"],
"next_actions": ["possible_actions"]
}
密钥管理
- 创建了安全的配置管理系统: SecureConfig 类用于加密存储敏感信息 使用 Fernet 对称加密 适当的文件权限管理(Windows 和 Unix)
- 实现了配置加载器: 从 YAML 文件加载基本配置 从加密存储加载敏感信息 支持环境变量覆盖
- 建立了清晰的配置优先级: API 密钥:环境变量 > 安全存储 > YAML 配置 API 基础 URL:环境变量 > API 配置 > 提供商默认值
- 完成了全面的测试覆盖: 安全配置的加密/解密 文件权限测试 配置优先级测试 API 设置测试
- 添加了必要的依赖: cryptography 用于加密 pywin32 用于 Windows 安全性 PyYAML 用于配置文件
- 这个实现提供了: 更好的安全性:敏感信息使用加密存储 灵活性:多种配置方式和清晰的优先级 跨平台支持:同时支持 Windows 和 Unix 良好的测试覆盖
测试
pytest tests/test_config.py -v
License
MIT License