Building AI agents, atomically
update readme, add documentation to example, modify tool interface agent to not use "tool" messages to ensure more compatibility
KennyVaneetveldeecb7305d7ffa
diff --git a/README.md b/README.mdindex c790b96..695a740 100644--- a/README.md+++ b/README.md@@ -30,6 +30,25 @@ Further examples can be found in the [examples](./examples/) directory.### DocsThe documentation can be found in the [docs](./docs/) directory. Here you will find both API documentation and guides.+## Instructor & Model Compatibility+Atomic Agents depends on the [Instructor](https://github.com/jxnl/instructor) package. This means that in all examples where OpenAI is used, any other API supported by Instructor can be used, such as Cohere, Anthropic, Gemini, and more. For a complete list please refer to the instructor documentation on its [GitHub page](https://github.com/jxnl/instructor).++Additionally, Atomic Agents should work with Ollama or LMStudio. If the default settings do not work due to your local server not supporting tool-calling, you can set the `mode` to JSON. For example:++```python+from instructor import BaseChatAgent, Mode++agent = BaseChatAgent(+ client=instructor.from_openai(+ openai.OpenAI(+ base_url='http://localhost:1234/v1', api_key='local'+ ),+ mode=Mode.JSON+ ),+ model='localmodel',+)+```+## ContributingWe welcome contributions! Please follow these steps to contribute:@@ -41,4 +60,4 @@ We welcome contributions! Please follow these steps to contribute:6. Open a pull request## License-This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\ No newline at end of file+This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.diff --git a/atomic_agents/agents/tool_interface_agent.py b/atomic_agents/agents/tool_interface_agent.pyindex 6f42723..ed21c53 100644--- a/atomic_agents/agents/tool_interface_agent.py+++ b/atomic_agents/agents/tool_interface_agent.py@@ -1,3 +1,4 @@+import jsonfrom pydantic import Field, create_modelfrom atomic_agents.agents.base_chat_agent import BaseChatAgentfrom atomic_agents.lib.components.system_prompt_generator import SystemPromptGenerator, SystemPromptInfo@@ -78,12 +79,14 @@ class ToolInterfaceAgent(BaseChatAgent):"""tool_input = self.get_response(response_model=self.tool_instance.input_schema)formatted_tool_input = format_tool_message(tool_input)- self.memory.add_message('assistant', '', tool_message=formatted_tool_input, tool_id=formatted_tool_input['id'])++ self.memory.add_message('assistant', 'TOOL CALL: ' + json.dumps(formatted_tool_input))tool_output = self.tool_instance.run(tool_input)- self.memory.add_message('tool', tool_output.model_dump_json(), tool_id=formatted_tool_input['id'])+ self.memory.add_message('assistant', 'TOOL RESPONSE: ' + tool_output.model_dump_json())if self.return_raw_output:return tool_output+ self.memory.add_message('assistant', 'I will now formulate a response for the user based on the tool output.')response = self.get_response(response_model=self.output_schema)return response\ No newline at end of filediff --git a/examples/minimal_chatbot.py b/examples/minimal_chatbot.pyindex a6d0d67..aee17cb 100644--- a/examples/minimal_chatbot.py+++ b/examples/minimal_chatbot.py@@ -1,20 +1,32 @@from rich.console import Console-from atomic_agents.agents.base_chat_agent import BaseChatAgentimport instructorimport openai-console = Console()+# `BaseChatAgent` is the core class for creating chat agents in the Atomic Agents framework.+from atomic_agents.agents.base_chat_agent import BaseChatAgent+# Create an instance of `BaseChatAgent` with default settings.+# The `from_openai` function wraps the OpenAI client to work seamlessly with the Atomic Agents framework.+# `openai.OpenAI()` creates a client instance for the OpenAI API.+# The `model` parameter specifies the language model to use, in this case, 'gpt-3.5-turbo'.agent = BaseChatAgent(client=instructor.from_openai(openai.OpenAI()),model='gpt-3.5-turbo',)+# Initialize a `Console` object for rich text output in the terminal.+console = Console()++# Start an infinite loop to keep the chatbot running until the user decides to exit.while True:+ # Prompt the user for input.user_input = input('You: ')- if user_input.lower() in ['exit', 'quit']:+ # Check if the user wants to exit the chat.+ if user_input.lower() in ['/exit', '/quit']:print('Exiting chat...')break+ # Process the user input through the chat agent to get a response.response = agent.run(user_input)+ # Use the `console` object to print the agent's response in a rich format.console.print(f'Agent: {response.response}')\ No newline at end of file