Skip to content

Building AI agents, atomically

Fix bug in SystemPromptGenerator and add date fields in SearXNG tool

KennyVaneetvelde65474e87d4f3
diff --git a/atomic_agents/lib/components/system_prompt_generator.py b/atomic_agents/lib/components/system_prompt_generator.py
index 76aca99..0f3eca6 100644
--- a/atomic_agents/lib/components/system_prompt_generator.py
+++ b/atomic_agents/lib/components/system_prompt_generator.py
@@ -29,15 +29,15 @@ class SystemPromptGenerator:
if self.system_prompt_info.background:
system_prompt += '# IDENTITY and PURPOSE\n'
- system_prompt += f'- {'\n-'.join(self.system_prompt_info.background)}\n\n'
+ system_prompt += '- ' + '\n- '.join(self.system_prompt_info.background) + '\n\n'
if self.system_prompt_info.steps:
system_prompt += '# INTERNAL ASSISTANT STEPS\n'
- system_prompt += f'- {'\n-'.join(self.system_prompt_info.steps)}\n\n'
+ system_prompt += '- ' + '\n- '.join(self.system_prompt_info.steps) + '\n\n'
if self.system_prompt_info.output_instructions:
system_prompt += '# OUTPUT INSTRUCTIONS\n'
- system_prompt += f'- {'\n-'.join(self.system_prompt_info.output_instructions)}\n\n'
+ system_prompt += '- ' + '\n- '.join(self.system_prompt_info.output_instructions) + '\n\n'
if self.dynamic_info_providers:
system_prompt += '# EXTRA INFORMATION AND CONTEXT\n'
@@ -45,6 +45,25 @@ class SystemPromptGenerator:
info = provider.get_info()
if info:
system_prompt += f'## {provider.title}\n'
- system_prompt += f'{info}\n\n'
+ system_prompt += f'{info}\n'
- return system_prompt
\ No newline at end of file
+ return system_prompt
+
+if __name__ == "__main__":
+ system_prompt = SystemPromptInfo(
+ background=[
+ 'This assistant is a general-purpose AI designed to be helpful and friendly.',
+ ],
+ steps=[
+ 'Understand the user\'s input and provide a relevant response.',
+ 'Respond to the user.'
+ ],
+ output_instructions=[
+ 'Provide helpful and relevant information to assist the user.',
+ 'Be friendly and respectful in all interactions.',
+ 'Always answer in rhyming verse. Preferably in alexandrine verse.'
+ ]
+ )
+ system_prompt_generator = SystemPromptGenerator(system_prompt)
+
+ print(system_prompt_generator.generate_prompt())
diff --git a/atomic_agents/lib/tools/search/searx_tool.py b/atomic_agents/lib/tools/search/searx_tool.py
index 3cd2b46..53b6825 100644
--- a/atomic_agents/lib/tools/search/searx_tool.py
+++ b/atomic_agents/lib/tools/search/searx_tool.py
@@ -116,6 +116,10 @@ class SearxNGSearchTool(BaseTool):
continue
if result['url'] not in seen_urls:
unique_results.append(result)
+ if 'metadata' in result:
+ result['title'] = result['metadata'] + ' - ' + result['title']
+ if 'publishedDate' in result and result['publishedDate']:
+ result['title'] = 'Date: ' + result['publishedDate'] + ' - ' + result['title']
seen_urls.add(result['url'])
# Filter results to include only those with the correct category if it is set
@@ -147,7 +151,7 @@ if __name__ == "__main__":
result = client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=SearxNGSearchTool.input_schema,
- messages=[{"role": "user", "content": "Search for the latest PC gaming news of May 2024 using 3 different queries."}],
+ messages=[{"role": "user", "content": "Search for the latest AI news."}],
)
rich_console.print(f"Search queries: {result.queries}")