Create Your First Synthora Chat Agent π€#
This tutorial will guide you through creating a basic chat agent using Synthora. Weβll go through the setup and testing process step by step.
1. Environment Setup#
First, letβs import the necessary libraries and set up our environment:
[1]:
import json
import os
import warnings
from synthora.agents import ReactAgent
from synthora.callbacks import RichOutputHandler
from synthora.configs import AgentConfig
2. API Key Configuration#
Set up your OpenAI API key. Make sure to replace it with your own key:
[4]:
warnings.filterwarnings("ignore")
os.environ["OPENAI_API_KEY"] = "<your-openai-api-key>"
Chat with Agent#
[5]:
agent = ReactAgent.default("You are a chatbot")
agent.run("Hello, how are you?").unwrap()
[5]:
"Hello! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you with anything you need. How can I assist you today?"
And thatβs it, folks!#
Youβve reached the end of this epic journey. Youβve set up your environment, configured your API key, created your agent, and even had a delightful conversation with it. What more could you possibly need? A cup of coffee, perhaps? βοΈ
But seriously, youβre all set! Go forth and create amazing chat agents. The world is your oyster. π¦ͺ
Tutorial over. Mic drop. π€π₯
3. Load Agent Configuration#
Weβll use a basic YAML configuration. Make sure you have created these two configuration files:
basic_agent.yaml:
name: basic-assistant
type: vanilla
model: !include basic_model.yaml
prompt: "You are an AI Assistant. You are here to help me with my queries."
basic_model.yaml:
name: basic-model
model_type: gpt-4
backend: openai_chat
backend_config:
api_key: "your-api-key"
config:
temperature: 0
top_p: 1.0
stream: true
[3]:
config = AgentConfig.from_file(
"../../../examples/agents/configs/react_agent.yaml"
)
print(json.dumps(config.model_dump(), indent=2))
{
"name": "WebSearcher",
"type": "react",
"description": "This agent is a simple AI assistant that can help you search the web.",
"model": {
"model_type": "gpt-4o",
"name": "searcher",
"backend": "openai_chat",
"config": {
"temperature": 0,
"top_p": 1.0,
"stream": true
},
"backend_config": null
},
"prompt": "You are a task-solving assistant with access to tools. Follow these rules:\n\n- Start by generating a \"Thought\" to explain your reasoning about how to solve the problem, and why you are using the tool.\n- Then call the necessary tool to solve the problem.\n- If you determine that no further tools are required and the task is complete, call the \"finish\" tool to provide the final response.\n\nYOU MUST Output the thought first!\n",
"tools": [
{
"target": "synthora.toolkits.SearchToolkit",
"trace": true,
"args": {}
}
]
}
4. Create Agent Instance#
Now letβs create our agent instance and add an output handler for beautiful formatting:
[4]:
agent = ReactAgent.from_config(config)
handler = RichOutputHandler()
agent.add_handler(handler)
5. Test the Conversation#
Letβs test our agent with a simple question:
[5]:
response = agent.run("What is artificial intelligence?")
β Έ searcher is thinking...
βββββββββββββββββββββββββββββββββββββββββββββββββββββ finish ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β Artificial intelligence (AI) is the intelligence exhibited by machines, particularly computer systems. It is a β β field of research in computer science focused on developing methods and software that enable machines to β β perceive their environment and use learning and intelligence to take actions that maximize their chances of β β achieving defined goals. High-profile applications of AI include advanced web search engines, recommendation β β systems, voice interaction systems, autonomous vehicles, generative and creative tools, and superhuman play in β β strategy games. AI research is divided into subfields centered around specific goals and tools. β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββ WebSearcher' Response: βββββββββββββββββββββββββββββββββββββββββββββ β Artificial intelligence (AI) is the intelligence exhibited by machines, particularly computer systems. It is a β β field of research in computer science focused on developing methods and software that enable machines to β β perceive their environment and use learning and intelligence to take actions that maximize their chances of β β achieving defined goals. High-profile applications of AI include advanced web search engines, recommendation β β systems, voice interaction systems, autonomous vehicles, generative and creative tools, and superhuman play in β β strategy games. AI research is divided into subfields centered around specific goals and tools. β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Congratulations!#
Youβve successfully created and run your first Synthora chat agent!
Next Steps:#
Try different prompts
Adjust model parameters
Add more capabilities (like search functionality)
For more examples and documentation, visit our official documentation.