Skip to content

Building AI agents, atomically

Update orchestrator notebook

KennyVaneetvelde473e05ad0833
diff --git a/examples/notebooks/orchestrator.ipynb b/examples/notebooks/orchestrator.ipynb
index a47dd7f..c77a6d0 100644
--- a/examples/notebooks/orchestrator.ipynb
+++ b/examples/notebooks/orchestrator.ipynb
@@ -54,7 +54,7 @@
"- `ChatMemory`: Manages the chat history.\n",
"- `BaseChatAgent`: The base class to create a custom chatbot. Can be extended for additional functionality if needed.\n",
"- `SystemPromptGenerator` and `SystemPromptInfo`: To define and generate system prompts.\n",
- "- `BaseTool`, `CalculatorTool`, `SearxNGSearchTool`: Tools that the orchestrator agent can use to perform tasks."
+ "- `BaseTool`, `CalculatorTool`, `SerperSearchTool`: Tools that the orchestrator agent can use to perform tasks."
]
},
{
@@ -74,7 +74,7 @@
"import openai\n",
"from atomic_agents.lib.tools.base import BaseTool\n",
"from atomic_agents.lib.tools.calculator_tool import CalculatorTool, CalculatorToolSchema\n",
- "from atomic_agents.lib.tools.search.searx_tool import SearxNGSearchTool, SearxNGSearchToolConfig, SearxNGSearchToolSchema"
+ "from atomic_agents.lib.tools.search.serper_tool import SerperSearchTool, SerperSearchToolConfig, SerperSearchToolSchema"
]
},
{
@@ -83,8 +83,25 @@
"source": [
"## Step 3: Define System Prompt Information\n",
"\n",
- "We will define the system prompt information including background, steps, and output instructions. This helps the orchestrator agent understand how to respond to user inputs and manage tasks.\n",
- "In this example, we will define a system prompt that asks the orchestrator agent to respond to user inputs in rhyming verse and manage tasks efficiently."
+ "In this step, we will define the system prompt information including background, steps, and output instructions. This helps the orchestrator agent understand how to respond to user inputs and manage tasks."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Tool Definition\n",
+ "\n",
+ "First, we define the tools that the orchestrator agent can use. These tools will help the agent perform various tasks such as searching the web or performing calculations."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### Serper Setup\n",
+ "\n",
+ "Set up your Serper API key. This key is required to access Serper's search capabilities."
]
},
{
@@ -93,16 +110,66 @@
"metadata": {},
"outputs": [],
"source": [
- "search_tool = SearxNGSearchTool(SearxNGSearchToolConfig(base_url=os.getenv('SEARXNG_BASE_URL'), max_results=10))\n",
- "calculator_tool = CalculatorTool()\n",
+ "##################################################################\n",
+ "# ENTER YOUR SERPER API KEY BELOW, OR SET IT AS AN ENVIRONMENT VARIABLE #\n",
+ "##################################################################\n",
+ "SERPER_API_KEY = ''\n",
+ "if not SERPER_API_KEY:\n",
+ " # Get the environment variable\n",
+ " SERPER_API_KEY = os.getenv('SERPER_API_KEY')\n",
+ "\n",
+ "if not SERPER_API_KEY:\n",
+ " raise ValueError('API key is not set. Please set the API key as a static variable or in the environment variable SERPER_API_KEY.')\n",
"\n",
+ "search_tool = SerperSearchTool(SerperSearchToolConfig(api_key=SERPER_API_KEY, max_results=10))\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Create the calculator tool. This does not require any special configuration.\n",
+ "calculator_tool = CalculatorTool()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### Create the tool info provider"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
"class ToolInfoProvider(SystemPromptContextProviderBase): \n",
" def get_info(self) -> str:\n",
" response = 'The available tools are:\\n'\n",
" for tool in [search_tool, calculator_tool]:\n",
" response += f'- {tool.tool_name}: {tool.tool_description}\\n'\n",
- " return response\n",
+ " return response"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### System Prompt Generator\n",
"\n",
+ "Next, we define the system prompt information including background, steps, output instructions and the ToolInfoProvider we defined above. This helps the orchestrator agent understand how to respond to user inputs and manage tasks."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
"# Define system prompt information including background, steps, and output instructions\n",
"system_prompt = SystemPromptInfo(\n",
" background=[\n",
@@ -124,8 +191,15 @@
")\n",
"\n",
"# Initialize the system prompt generator with the defined system prompt and dynamic info providers\n",
- "system_prompt_generator = SystemPromptGenerator(system_prompt)\n",
- "\n",
+ "system_prompt_generator = SystemPromptGenerator(system_prompt)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
"# Test out the system prompt generator\n",
"from rich.markdown import Markdown\n",
"from rich.console import Console\n",
@@ -160,9 +234,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Step 5: Set Up API Key and Create Orchestrator Agent\n",
+ "## Step 5: Set Up API Keys\n",
"\n",
- "To use the **OpenAI** API, you need to set up your API key. You can either enter it directly in the code or set it as an environment variable. Additionally, you can choose other clients such as **Anthropic**, **Mistral**, etc. For a full list, check out the [Instructor library docs](https://github.com/jxnl/instructor)."
+ "To use the **OpenAI** and **Serper** APIs, you need to set up your API keys. You can either enter them directly in the code or set them as environment variables."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### OpenAI Setup\n",
+ "\n",
+ "Set up your OpenAI API key. This key is required to access OpenAI's language models."
]
},
{
@@ -172,7 +255,7 @@
"outputs": [],
"source": [
"##################################################################\n",
- "# ENTER YOUR API KEY BELOW, OR SET IT AS AN ENVIRONMENT VARIABLE #\n",
+ "# ENTER YOUR OPENAI API KEY BELOW, OR SET IT AS AN ENVIRONMENT VARIABLE #\n",
"##################################################################\n",
"API_KEY = ''\n",
"if not API_KEY:\n",
@@ -182,10 +265,26 @@
"if not API_KEY:\n",
" raise ValueError('API key is not set. Please set the API key as a static variable or in the environment variable OPENAI_API_KEY.')\n",
"\n",
- "client = instructor.from_openai(openai.OpenAI(api_key=API_KEY))\n",
+ "client = instructor.from_openai(openai.OpenAI(api_key=API_KEY))\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Step 6: Create Orchestrator Agent\n",
"\n",
+ "Now that we have set up the API keys, we can create the orchestrator agent. This agent will use the OpenAI client, system prompt generator, and chat memory to manage tasks and respond to user inputs."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
"class ResponseSchema(BaseModel):\n",
- " chosen_schema: Union[BaseChatAgentResponse, SearxNGSearchToolSchema, CalculatorToolSchema] = Field(..., description='The response from the chat agent.')\n",
+ " chosen_schema: Union[BaseChatAgentResponse, SerperSearchToolSchema, CalculatorToolSchema] = Field(..., description='The response from the chat agent.')\n",
" \n",
" class Config:\n",
" title = 'ResponseSchema'\n",
@@ -214,7 +313,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Step 6: Main Chat Loop\n",
+ "## Step 7: Main Chat Loop\n",
"\n",
"We will create a main chat loop for testing the orchestrator agent. This loop will allow you to interact with the chatbot in real-time.\n",
"To exit the loop, type `/exit` or `/quit`."