picogent-py/picogent/config.py
Markov 5417980b76 Initial implementation of PicoGent - minimal AI coding agent
- Implemented ReAct loop in agent.py
- Added Anthropic provider using httpx (no SDK)
- Created tools: read, write, edit, bash
- Added session management with JSONL format
- Included configuration system with env var support
- Added CLI interface and example usage
- Minimal dependencies: only httpx
2026-02-22 23:18:02 +01:00

59 lines
1.9 KiB
Python

"""
Configuration management for PicoGent
"""
import json
import os
from dataclasses import dataclass
from typing import Optional, Dict, Any
@dataclass
class Config:
"""Configuration for PicoGent agent"""
provider: str = "anthropic"
model: str = "claude-sonnet-4-20250514"
api_key: str = "env:ANTHROPIC_API_KEY"
max_tokens: int = 8192
max_iterations: int = 20
workspace: str = "."
system_prompt: str = "You are a helpful coding assistant."
@classmethod
def from_file(cls, config_path: str) -> "Config":
"""Load configuration from JSON file"""
if not os.path.exists(config_path):
raise FileNotFoundError(f"Config file not found: {config_path}")
with open(config_path, 'r') as f:
data = json.load(f)
# Resolve environment variables in API key
api_key = data.get('api_key', '')
if api_key.startswith('env:'):
env_var = api_key[4:] # Remove 'env:' prefix
api_key = os.getenv(env_var, '')
if not api_key:
raise ValueError(f"Environment variable {env_var} is not set")
return cls(
provider=data.get('provider', 'anthropic'),
model=data.get('model', 'claude-sonnet-4-20250514'),
api_key=api_key,
max_tokens=data.get('max_tokens', 8192),
max_iterations=data.get('max_iterations', 20),
workspace=data.get('workspace', '.'),
system_prompt=data.get('system_prompt', 'You are a helpful coding assistant.')
)
def to_dict(self) -> Dict[str, Any]:
"""Convert config to dictionary"""
return {
'provider': self.provider,
'model': self.model,
'api_key': self.api_key,
'max_tokens': self.max_tokens,
'max_iterations': self.max_iterations,
'workspace': self.workspace,
'system_prompt': self.system_prompt
}