picogent-py/picogent/providers/base.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

61 lines
1.6 KiB
Python

"""
Base provider class for AI providers
"""
from abc import ABC, abstractmethod
from typing import List, Dict, Any, Optional
from ..config import Config
class BaseProvider(ABC):
"""Base class for AI providers"""
def __init__(self, config: Config):
self.config = config
@abstractmethod
async def chat_completion(
self,
messages: List[Dict[str, Any]],
tools: Optional[List[Dict[str, Any]]] = None,
system_prompt: Optional[str] = None
) -> Dict[str, Any]:
"""
Get chat completion from the provider
Args:
messages: List of messages in the conversation
tools: Optional list of available tools
system_prompt: Optional system prompt
Returns:
Dictionary containing response with 'content' and optional 'tool_calls'
"""
pass
@abstractmethod
def parse_tool_calls(self, response: Dict[str, Any]) -> List[Dict[str, Any]]:
"""
Parse tool calls from provider response
Args:
response: Provider response
Returns:
List of tool calls with 'id', 'name', and 'arguments'
"""
pass
@abstractmethod
def format_tool_result(self, tool_call_id: str, result: str) -> Dict[str, Any]:
"""
Format tool result for next request
Args:
tool_call_id: ID of the tool call
result: Result of tool execution
Returns:
Formatted message for the provider
"""
pass