Spaces:
Sleeping
Sleeping
Add configuration, graph, runner, and tools modules to enhance agent functionality. Introduce a Configuration class for managing parameters, implement an AgentRunner for executing the agent graph, and create tools for general search and mathematical calculations. Update test_agent.py to reflect new import paths and improve overall code organization.
13388e5
unverified
| """Define the configurable parameters for the agent.""" | |
| from __future__ import annotations | |
| import os | |
| from dataclasses import dataclass, fields | |
| from typing import Optional | |
| from langchain_core.runnables import RunnableConfig | |
| class Configuration: | |
| """The configuration for the agent.""" | |
| # API configuration | |
| api_base: Optional[str] = "http://localhost:11434" | |
| api_key: Optional[str] = os.getenv("MODEL_API_KEY") | |
| model_id: Optional[str] = ( | |
| f"ollama/{os.getenv('OLLAMA_MODEL', 'qwen2.5-coder:0.5b')}" | |
| ) | |
| # Agent configuration | |
| my_configurable_param: str = "changeme" | |
| def from_runnable_config( | |
| cls, config: Optional[RunnableConfig] = None | |
| ) -> Configuration: | |
| """Create a Configuration instance from a RunnableConfig object.""" | |
| configurable = (config.get("configurable") or {}) if config else {} | |
| _fields = {f.name for f in fields(cls) if f.init} | |
| return cls(**{k: v for k, v in configurable.items() if k in _fields}) | |