Full Example
Walk through setting up an agent that uses Asteroid, from scratch
Example Agent
In this example, we will demonstrate how to create an AI assistant that can perform tasks such as searching the internet, sending emails, creating calendar events, and booking flights. We will use the asteroid-sdk
Python SDK to supervise tool executions with the supervise()
decorator, ensuring compliance with specified policies or requiring human approval when necessary.
Overview
The assistant agent is designed to:
- Interact with the user and understand their requests.
- Use tools to perform specific actions like searching the internet or sending emails.
- Utilize the
supervise()
decorator to supervise tool executions. - Allow supervision and approval of actions in real-time through the Asteroid web interface.
Key Components
1. Supervisors
Supervisors are functions that approve, modify, or escalate tool calls based on certain policies or checks. We define custom supervisors and use built-in ones.
check_email_address_supervisor
: A custom supervisor that checks if an email address is in a whitelist before sending an email.
- Built-in Supervisors: We also use
llm_supervisor
andhuman_supervisor
from theasteroid-sdk
SDK.
2. Tools
We define several tools that the assistant can use. Each tool is supervised to ensure compliance with policies.
internet_search
: Searches the internet using DuckDuckGo.
send_email
: Sends an email, supervised to check recipient and content.
create_calendar_event
: Creates a calendar event, supervised to ensure correctness.
book_flight
: Books a flight ticket, always requiring human approval.
3. Assistant Agent
The assistant agent interacts with the user, utilizes the tools, and handles OpenAI responses.
- Creating OpenAI Tool Definitions: We convert our tool functions into OpenAI’s expected schema.
- Chat Function with OpenAI: Handles interaction with the OpenAI GPT model.
- Executing Tool Calls: Executes tool calls as decided by the assistant.
- Starting the Chatbot: The main loop that starts the chatbot and handles user interaction.
4. Running the Assistant
We set up the environment and start the assistant.
Supervising the Agent in Real-Time
Head to the Asteroid Platform and find the agent that you configured. You will be able to observe the execution of the agent and interact with it via human reviews where needed.
Conclusion
By using the supervise()
decorator and Asteroid, we can ensure that our AI assistant operates within predefined policies and allows for human oversight when necessary. This example demonstrates how to integrate supervised tool executions into an AI assistant, enhancing safety and reliability.