diff --git a/llama_toolchain/agentic_system/meta_reference/agentic_system.py b/llama_toolchain/agentic_system/meta_reference/agentic_system.py index ae1d282aa6..5252e75151 100644 --- a/llama_toolchain/agentic_system/meta_reference/agentic_system.py +++ b/llama_toolchain/agentic_system/meta_reference/agentic_system.py @@ -47,6 +47,7 @@ async def get_provider_impl(config: AgenticSystemConfig, deps: Dict[Api, Provide ), f"Unexpected config type: {type(config)}" impl = MetaReferenceAgenticSystemImpl( + config, deps[Api.inference], deps[Api.safety], ) @@ -58,7 +59,10 @@ async def get_provider_impl(config: AgenticSystemConfig, deps: Dict[Api, Provide class MetaReferenceAgenticSystemImpl(AgenticSystem): - def __init__(self, inference_api: Inference, safety_api: Safety): + def __init__( + self, config: AgenticSystemConfig, inference_api: Inference, safety_api: Safety + ): + self.config = config self.inference_api = inference_api self.safety_api = safety_api @@ -77,9 +81,15 @@ async def create_agentic_system( for dfn in cfg.available_tools: if isinstance(dfn.tool_name, BuiltinTool): if dfn.tool_name == BuiltinTool.wolfram_alpha: - tool = WolframAlphaTool(os.environ.get("WOLFRAM_ALPHA_API_KEY")) + key = self.config.wolfram_api_key + if not key: + raise ValueError("Wolfram API key not defined in config") + tool = WolframAlphaTool(key) elif dfn.tool_name == BuiltinTool.brave_search: - tool = BraveSearchTool(os.environ.get("BRAVE_SEARCH_API_KEY")) + key = self.config.brave_search_api_key + if not key: + raise ValueError("Brave API key not defined in config") + tool = BraveSearchTool(key) elif dfn.tool_name == BuiltinTool.code_interpreter: tool = CodeInterpreterTool() elif dfn.tool_name == BuiltinTool.photogen: diff --git a/llama_toolchain/agentic_system/meta_reference/config.py b/llama_toolchain/agentic_system/meta_reference/config.py index 3497840219..cff22d03dd 100644 --- a/llama_toolchain/agentic_system/meta_reference/config.py +++ b/llama_toolchain/agentic_system/meta_reference/config.py @@ -4,9 +4,11 @@ # This source code is licensed under the terms described in the LICENSE file in # the root directory of this source tree. +from typing import Optional + from pydantic import BaseModel class AgenticSystemConfig(BaseModel): - # placeholder, no separate configuration is needed for now - pass + brave_search_api_key: Optional[str] = None + wolfram_api_key: Optional[str] = None diff --git a/llama_toolchain/distribution/distribution.py b/llama_toolchain/distribution/distribution.py index f92547ba7e..f96d0cac6c 100644 --- a/llama_toolchain/distribution/distribution.py +++ b/llama_toolchain/distribution/distribution.py @@ -26,7 +26,6 @@ # `llama-toolchain` is automatically installed by the installation script. SERVER_DEPENDENCIES = [ "fastapi", - "python-dotenv", "uvicorn", ] diff --git a/llama_toolchain/distribution/server.py b/llama_toolchain/distribution/server.py index d1140e6a08..8707fa9edd 100644 --- a/llama_toolchain/distribution/server.py +++ b/llama_toolchain/distribution/server.py @@ -27,7 +27,6 @@ import fire import httpx import yaml -from dotenv import load_dotenv from fastapi import FastAPI, HTTPException, Request, Response from fastapi.exceptions import RequestValidationError @@ -42,8 +41,6 @@ from .registry import resolve_distribution_spec -load_dotenv() - def is_async_iterator_type(typ): if hasattr(typ, "__origin__"):