Skip to content

Building AI agents, atomically

Get rid of SystemPromptInfo in examples

KennyVaneetveldef1c71a9dffd5
diff --git a/examples/notebooks/quickstart.ipynb b/examples/notebooks/quickstart.ipynb
index 3990075..31255ef 100644
--- a/examples/notebooks/quickstart.ipynb
+++ b/examples/notebooks/quickstart.ipynb
@@ -67,7 +67,7 @@
"import openai\n",
"from atomic_agents.lib.components.agent_memory import AgentMemory\n",
"from atomic_agents.agents.base_agent import BaseAgent, BaseAgentConfig\n",
- "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo"
+ "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator"
]
},
{
@@ -88,7 +88,7 @@
"metadata": {},
"outputs": [],
"source": [
- "system_prompt = SystemPromptInfo(\n",
+ "system_prompt_generator = SystemPromptGenerator(\n",
" background=[\n",
" 'This assistant is a general-purpose AI designed to be helpful and friendly.',\n",
" ],\n",
@@ -102,7 +102,6 @@
" 'Always answer in rhyming verse.'\n",
" ]\n",
")\n",
- "system_prompt_generator = SystemPromptGenerator(system_prompt)\n",
"\n",
"from rich.markdown import Markdown\n",
"Markdown(system_prompt_generator.generate_prompt())"
diff --git a/examples/notebooks/what_is_atomic_agents.ipynb b/examples/notebooks/what_is_atomic_agents.ipynb
index 6e17cdc..7d1a5eb 100644
--- a/examples/notebooks/what_is_atomic_agents.ipynb
+++ b/examples/notebooks/what_is_atomic_agents.ipynb
@@ -90,7 +90,7 @@
"Next, we will import the necessary components for creating the chatbot. Each component serves a specific purpose:\n",
"- `AgentMemory`: Manages the chat history.\n",
"- `BaseAgent`: 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."
+ "- `SystemPromptGenerator`: To define and generate system prompts."
]
},
{
@@ -100,7 +100,7 @@
"outputs": [],
"source": [
"import os\n",
- "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo"
+ "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator"
]
},
{
@@ -120,7 +120,7 @@
"source": [
"from rich.console import Console\n",
"\n",
- "system_prompt = SystemPromptInfo(\n",
+ "system_prompt_generator = SystemPromptGenerator(\n",
" background=[\n",
" 'This assistant is a general-purpose AI designed to be helpful and friendly.',\n",
" ],\n",
@@ -134,7 +134,6 @@
" 'Always answer in rhyming verse.'\n",
" ]\n",
")\n",
- "system_prompt_generator = SystemPromptGenerator(system_prompt)\n",
"\n",
"Console().print(system_prompt_generator.generate_prompt())"
]
@@ -538,24 +537,23 @@
" self.output_schema = self.tool_instance.output_schema\n",
" \n",
" self.system_prompt_generator = SystemPromptGenerator(\n",
- " system_prompt_info=SystemPromptInfo(\n",
- " background=[\n",
- " f\"This AI agent is designed to interact with the {self.tool_instance.tool_name} tool.\",\n",
- " f\"Tool description: {self.tool_instance.tool_description}\"\n",
- " ],\n",
- " steps=[\n",
- " \"Get the user input.\",\n",
- " \"Convert the input to the proper parameters to call the tool.\",\n",
- " \"Call the tool with the parameters.\",\n",
- " \"Respond to the user\"\n",
- " ],\n",
- " output_instructions=[\n",
- " \"Make sure the tool call will maximize the utility of the tool in the context of the user input.\",\n",
- " \"Process the output of the tool into a human readable format and/or use it to respond to the user input.\" if self.return_raw_output else \"Return the raw output of the tool.\"\n",
- " ]\n",
- " )\n",
+ " background=[\n",
+ " f\"This AI agent is designed to interact with the {self.tool_instance.tool_name} tool.\",\n",
+ " f\"Tool description: {self.tool_instance.tool_description}\"\n",
+ " ],\n",
+ " steps=[\n",
+ " \"Get the user input.\",\n",
+ " \"Convert the input to the proper parameters to call the tool.\",\n",
+ " \"Call the tool with the parameters.\",\n",
+ " \"Respond to the user\"\n",
+ " ],\n",
+ " output_instructions=[\n",
+ " \"Make sure the tool call will maximize the utility of the tool in the context of the user input.\",\n",
+ " \"Process the output of the tool into a human readable format and/or use it to respond to the user input.\" if self.return_raw_output else \"Return the raw output of the tool.\"\n",
+ " ]\n",
" )\n",
" \n",
+ " \n",
" def _get_and_handle_response(self):\n",
" \"\"\"\n",
" Handles obtaining and processing the response from the tool.\n",
diff --git a/examples/notebooks/yelp_agent.ipynb b/examples/notebooks/yelp_agent.ipynb
index 76d3652..5ab6676 100644
--- a/examples/notebooks/yelp_agent.ipynb
+++ b/examples/notebooks/yelp_agent.ipynb
@@ -68,7 +68,7 @@
"from rich.console import Console\n",
"\n",
"from atomic_agents.lib.components.agent_memory import AgentMemory\n",
- "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo\n",
+ "from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator\n",
"from atomic_agents.agents.base_agent import BaseAgent, BaseAgentOutputSchema, BaseAgentConfig\n",
"from atomic_agents.lib.tools.yelp_restaurant_finder_tool import YelpSearchTool, YelpSearchToolConfig, YelpSearchToolInputSchema"
]
@@ -88,8 +88,8 @@
"metadata": {},
"outputs": [],
"source": [
- "# Define system prompt information including background, steps, and output instructions\n",
- "system_prompt = SystemPromptInfo(\n",
+ "# Initialize the system prompt generator with the defined system prompt and dynamic info providers\n",
+ "system_prompt_generator = SystemPromptGenerator(\n",
" background=[\n",
" 'This assistant is a restaurant finder AI designed to help users find the best restaurants based on their preferences by asking clarifying questions.',\n",
" ],\n",
@@ -124,9 +124,6 @@
"metadata": {},
"outputs": [],
"source": [
- "# Initialize the system prompt generator with the defined system prompt and dynamic info providers\n",
- "system_prompt_generator = SystemPromptGenerator(system_prompt)\n",
- "\n",
"# Initialize chat memory to store conversation history\n",
"memory = AgentMemory()\n",
"# Define initial memory with a greeting message from the assistant\n",
@@ -227,7 +224,7 @@
" system_prompt_generator=system_prompt_generator,\n",
" model='gpt-3.5-turbo',\n",
" memory=memory,\n",
- " output_schema=OutputSchema\n",
+ " output_schema=ResponseSchema\n",
" )\n",
")\n",
"\n",
diff --git a/examples/notebooks/youtube_knowledge_extraction.ipynb b/examples/notebooks/youtube_knowledge_extraction.ipynb
index ea8865d..20aea7d 100644
--- a/examples/notebooks/youtube_knowledge_extraction.ipynb
+++ b/examples/notebooks/youtube_knowledge_extraction.ipynb
@@ -101,8 +101,8 @@
"from typing import List, Optional\n",
"\n",
"from atomic_agents.agents.base_agent import BaseAgent, BaseAgentConfig\n",
- "from atomic_agents.lib.components.system_prompt_generator import SystemPromptContextProviderBase, SystemPromptGenerator, SystemPromptInfo\n",
- "from atomic_agents.lib.tools.yt_transcript_scraper import YouTubeTranscriptTool, YouTubeTranscriptToolConfig, YouTubeTranscriptToolInputSchema"
+ "from atomic_agents.lib.components.system_prompt_generator import SystemPromptContextProviderBase, SystemPromptGenerator\n",
+ "from atomic_agents.lib.tools.yt_transcript_scraper_tool import YouTubeTranscriptTool, YouTubeTranscriptToolConfig, YouTubeTranscriptToolInputSchema"
]
},
{
@@ -151,8 +151,7 @@
" return f'VIDEO TRANSCRIPT: \"{self.transcript}\"\\n\\nDURATION: {self.duration}\\n\\nMETADATA: {self.metadata}'\n",
" \n",
"transcript_provider = YtTranscriptProvider(title='YouTube Transcript')\n",
- "\n",
- "system_prompt_info = SystemPromptInfo(\n",
+ "system_prompt_generator = SystemPromptGenerator(\n",
" background=[\n",
" 'This Assistant is an expert at extracting knowledge and other insightful and interesting information from YouTube transcripts.'\n",
" ],\n",
@@ -213,7 +212,7 @@
"agent = BaseAgent(\n",
" config=BaseAgentConfig(\n",
" client=client,\n",
- " system_prompt_generator=SystemPromptGenerator(system_prompt_info),\n",
+ " system_prompt_generator=system_prompt_generator,\n",
" model='gpt-3.5-turbo',\n",
" output_schema=ResponseModel\n",
" )\n",
diff --git a/examples/product_finder.py b/examples/product_finder.py
index 8e8b464..afbc69d 100644
--- a/examples/product_finder.py
+++ b/examples/product_finder.py
@@ -7,8 +7,8 @@ import openai
from rich.console import Console
from atomic_agents.lib.components.agent_memory import AgentMemory
-from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo
-from atomic_agents.agents.base_agent import BaseAgent, BaseAgentOutputSchema, BaseAgentConfig
+from atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator
+from atomic_agents.agents.base_agent import BaseAgent, BaseAgentOutputSchema, BaseAgentConfig, BaseIOSchema
from atomic_agents.lib.tools.search.searxng_tool import SearxNGTool, SearxNGToolConfig, SearxNGToolInputSchema
# Configure logging
@@ -16,7 +16,7 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(level
logger = logging.getLogger(__name__)
# Define system prompt information
-system_prompt = SystemPromptInfo(
+system_prompt_generator = SystemPromptGenerator(
background=[
'This assistant is a product finder AI designed to help users find products based on their preferences by asking clarifying questions.',
],
@@ -28,15 +28,13 @@ system_prompt = SystemPromptInfo(
'Summarize the search results and provide recommendations to the user.',
],
output_instructions=[
+ 'Always think in steps before answering using internal reasoning.',
'Provide helpful and relevant information to assist the user.',
'Be friendly and respectful in all interactions.',
'Ensure that the chat responses are used to ask clarifying questions and gather information, and the search tool is used to find products.'
]
)
-# Initialize the system prompt generator
-system_prompt_generator = SystemPromptGenerator(system_prompt)
-
# Initialize chat memory
memory = AgentMemory()
initial_memory = [
@@ -53,8 +51,9 @@ client = instructor.from_openai(openai.OpenAI())
searxng_tool = SearxNGTool(SearxNGToolConfig(base_url=os.getenv('SEARXNG_BASE_URL'), max_results=5))
# Define a custom response schema
-class OutputSchema(BaseModel):
- chosen_schema: Union[BaseAgentOutputSchema, SearxNGToolInputSchema] = Field(..., description='The response from the chat agent.')
+class OutputSchema(BaseIOSchema):
+ internal_reasoning: List[str] = Field(..., description='The internal reasoning behind the response.')
+ chosen_schema: Union[BaseAgentOutputSchema, SearxNGToolInputSchema] = Field(..., description='The response from the chat agent. Every response must use chosen_schema to indicate the type of response (A chat message, or a search request)')
class Config:
title = 'OutputSchema'
@@ -64,7 +63,7 @@ class OutputSchema(BaseModel):
agent_config = BaseAgentConfig(
client=client,
system_prompt_generator=system_prompt_generator,
- model='gpt-3.5-turbo',
+ model='gpt-4o-mini',
memory=memory,
output_schema=OutputSchema
)
diff --git a/examples/system_prompt_generator_demo.py b/examples/system_prompt_generator_demo.py
index f293d33..6a8502e 100644
--- a/examples/system_prompt_generator_demo.py
+++ b/examples/system_prompt_generator_demo.py
@@ -1,6 +1,6 @@
from datetime import datetime
from unittest.mock import Mock
-from atomic_agents.lib.components.system_prompt_generator import SystemPromptContextProviderBase, SystemPromptGenerator, SystemPromptInfo
+from atomic_agents.lib.components.system_prompt_generator import SystemPromptContextProviderBase, SystemPromptGenerator
class CurrentDateProvider(SystemPromptContextProviderBase):
@@ -19,7 +19,7 @@ class LoremIpsumProvider(SystemPromptContextProviderBase):
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
)
-system_prompt = SystemPromptInfo(
+system_prompt_generator = SystemPromptGenerator(
background=[
'This assistant is a general-purpose AI designed to be helpful and friendly.',
],
@@ -38,5 +38,4 @@ system_prompt = SystemPromptInfo(
}
)
-system_prompt_generator = SystemPromptGenerator(system_prompt)
print(system_prompt_generator.generate_prompt())