Add MiniMax LLM integration and local .env support
- Add .env to .gitignore (API keys stay local) - Add LLM client with MiniMax and OpenAI support - Update config to load from environment variables - Wire up Architect agent to actually call the LLM - Add MiniMax API key to local .env file
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
"""Base agent class for Opus Orchestrator."""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Generic, TypeVar
|
||||
from typing import Any, Generic, Optional, TypeVar
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from opus_orchestrator.config import AgentConfig, get_config
|
||||
from opus_orchestrator.utils.llm import LLMClient, get_llm_client
|
||||
|
||||
|
||||
T = TypeVar("T", bound=BaseModel)
|
||||
@@ -23,9 +24,6 @@ class AgentResponse(BaseModel):
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class BaseAgent(ABC, Generic[T]):
|
||||
"""Base class for all Opus agents.
|
||||
|
||||
@@ -49,6 +47,14 @@ class BaseAgent(ABC, Generic[T]):
|
||||
self.system_prompt = system_prompt
|
||||
self.output_schema = output_schema
|
||||
self.config = config or get_config().agent
|
||||
self._llm_client: Optional[LLMClient] = None
|
||||
|
||||
@property
|
||||
def llm_client(self) -> LLMClient:
|
||||
"""Get or create LLM client."""
|
||||
if self._llm_client is None:
|
||||
self._llm_client = get_llm_client()
|
||||
return self._llm_client
|
||||
|
||||
@abstractmethod
|
||||
async def execute(self, input_data: Any, context: dict[str, Any]) -> AgentResponse:
|
||||
@@ -63,6 +69,31 @@ class BaseAgent(ABC, Generic[T]):
|
||||
"""
|
||||
pass
|
||||
|
||||
async def call_llm(
|
||||
self,
|
||||
system_prompt: str,
|
||||
user_prompt: str,
|
||||
temperature: Optional[float] = None,
|
||||
) -> str:
|
||||
"""Call the LLM with prompts.
|
||||
|
||||
Args:
|
||||
system_prompt: System prompt
|
||||
user_prompt: User prompt
|
||||
temperature: Optional temperature override
|
||||
|
||||
Returns:
|
||||
Generated text
|
||||
"""
|
||||
temp = temperature if temperature is not None else self.config.temperature
|
||||
|
||||
return await self.llm_client.complete(
|
||||
system_prompt=system_prompt,
|
||||
user_prompt=user_prompt,
|
||||
temperature=temp,
|
||||
max_tokens=self.config.max_tokens,
|
||||
)
|
||||
|
||||
def build_system_prompt(self, context: dict[str, Any]) -> str:
|
||||
"""Build the full system prompt with context.
|
||||
|
||||
@@ -104,3 +135,9 @@ class BaseAgent(ABC, Generic[T]):
|
||||
|
||||
Please complete this task following the methodology specified in your system prompt.
|
||||
"""
|
||||
|
||||
async def cleanup(self):
|
||||
"""Clean up resources."""
|
||||
if self._llm_client:
|
||||
await self._llm_client.close()
|
||||
self._llm_client = None
|
||||
|
||||
Reference in New Issue
Block a user