Autonomous Agents enable developers to build sophisticated applications that they previously could not. However, using these Agents in isolation is often insufficient for creating a truly useful app – the real use case is unlocked when you can combine them with other sources of computation or knowledge.
SuperAGI SDK client library simplifies the interaction between the SuperAGI API and applications developed using Python. The library provides a robust set of capabilities for managing AI agents and runs. Users can easily create, update, delete, and monitor agents, retrieve resources associated with a particular agent, and fine-tune their agent configurations for customized operations. The library also uses API key-based authentication to keep your operations secure.
Here’s how to get started:
⚙️ Working with Python client library:
To begin, install the SuperAGI-Client library using the “pip install superagi-client” command.
pip install superagi-client
Then, import the library and initialize the client with our API key, The URL endpoint is set to “https://app.superagi.com/” by default:
from superagi_client import Client
client = Client(api_key="YOUR_API_KEY", url="YOUR_OPTIONAL_URL")
To create an agent:
from superagi_client import AgentConfig
agent_config = AgentConfig(
name="Sample Agent",
description="A descriptive purpose of the agent.",
goal=["Define a specific task for the agent"],
instruction=["Provide additional guiding instructions"],
agent_workflow="Goal Based Workflow",
constraints=[],
tools=[{"name": "ToolName"}],
iteration_interval=500,
max_iterations=10,
model="gpt-4"
)
agent = client.create_agent(agent_config=agent_config)
⚙️Parameters for Agent Configuration:
Configure your agents using the following parameters:
name
: A string representing the name of the agent.description
: A brief description of the agent’s purpose.goal
: A list of goals/tasks you want the agent to achieve.instruction
: A list of specific instructions to guide the agent’s approach.agent_workflow
: Workflow type for the agent. Currently, only “Goal Based Workflow” is supported.constraints
: (Optional) A list of any constraints you want to place on the agent’s operations.tools
: A list of dictionaries where each dictionary defines a tool the agent can use. Example:{"name": "File Toolkit", "tools": ["Read File", "Write File"]}
.iteration_interval
: The time interval (in milliseconds) between each iteration/check by the agent.max_iterations
: The maximum number of iterations allowed for the agent.model
: The AI model to be used, e.g., “gpt-4”.
Once the agent is created, you can initiate its runs, monitor their statuses, and pause or resume them if required.
Starting an Agent Run:
agent_id = agent['agent_id'] run_agent = client.create_agent_run(agent_id=agent_id)
This starts an agent run and the run_agent contains the run_id
for the initiated run.
Checking the Status of Agent Runs:
run_status = client.get_agent_run_status(agent_id=agent_id)
This retrieves the status of the runs associated with the specified agent_id
. To filter specific runs or statuses, you can utilize the AgentRunFilter
type. For instance, to get the status of runs with specific run_ids
:
from superagi_client import AgentRunFilter
filter_config = AgentRunFilter(run_ids=[run_id_1, run_id_2])
run_status = client.get_agent_run_status(agent_id=agent_id, agent_run_filter=filter_config)
Pausing and Resuming Agent Runs:
If needed, you can pause specific agent runs and later resume them.
client.pause_agent(agent_id=agent_id, agent_run_ids=[run_id])
client.resume_agent(agent_id=agent_id, agent_run_ids=[run_id])
Updating an Agent’s Configuration:
Over time, if you want to update any agent’s parameters:
from superagi_client import AgentUpdateConfig
updated_config = AgentUpdateConfig(
name="Updated Agent Name",
goal=["New goal for the agent"] )
client.update_agent(agent_id=agent_id, agent_update_config=updated_config)
The AgentUpdateConfig
contains optional parameters allowing you to update only specific attributes of an agent.
Fetching Resources of Agent Runs:
To inspect the resources associated with certain runs:
resources = client.get_agent_run_resources(agent_run_ids=[run_id])
Data Types in SuperAGI-Client
These data types form the backbone of the SuperAGI-Client library. Proper understanding and utilization of these can significantly streamline your interactions with the SuperAGI platform.
1. AgentSchedule
AgentSchedule efines the scheduling attributes of an agent.
Attributes:
agent_id
: (Optional) An integer representing the ID of the agent.start_time
:datetime
indicating when the agent should begin its task.recurrence_interval
: (Optional) A string indicating how frequently the agent should be run (e.g., ‘daily’, ‘weekly’).expiry_date
: (Optional) Adatetime
indicating when the agent’s task schedule should expire.expiry_runs
: (Optional) An integer representing after how many runs the agent’s task should expire. By default, it’s set to -1 (indicating no expiration based on number of runs).
2. AgentConfig
AgentConfig represents the configuration attributes required to set up an agent.
Attributes:
name
: Name of the agent.description
: Brief description of the agent.project_id
: (Optional) Associated project ID.goal
: Goals or tasks you want the agent to achieve.instruction
: Specific instructions guiding the agent.agent_workflow
: Workflow type. Currently, “Goal Based Workflow” is supported.constraints
: (Optional) Constraints on the agent’s operations.tools
: Tools available for the agent.LTM_DB
: (Optional) Reference to a Long-Term Memory Database.exit
: (Optional) Conditions upon which the agent should terminate.permission_type
: (Optional) Permission level for the agent.iteration_interval
: Time between agent iterations.model
: AI model, e.g., “gpt-4”.schedule
: (Optional) Schedule details for the agent.max_iterations
: Maximum iterations for the agent.user_timezone
: (Optional) User’s timezone.knowledge
: (Optional) Reference to the agent’s knowledge base.
3. AgentUpdateConfig
This describes the configuration for updating an existing agent. All parameters are optional, which means you only need to include the ones you want to update.
Attributes:
name
: (Optional) Updated name of the agent.description
: (Optional) New or revised description for the agent.project_id
: (Optional) If you wish to change or assign a project ID.goal
: (Optional) Modify or redefine the goals or tasks you want the agent to achieve.instruction
: (Optional) Change or provide new specific instructions guiding the agent.agent_workflow
: (Optional) New workflow type if changing. Currently, “Goal Based Workflow” is supported.constraints
: (Optional) If you need to add or modify constraints on the agent’s operations.tools
: (Optional) Update or change the tools available for the agent.LTM_DB
: (Optional) Change or update the reference to a Long-Term Memory Database.exit
: (Optional) Modify conditions upon which the agent should terminate.permission_type
: (Optional) Change the permission level for the agent.iteration_interval
: (Optional) Modify the time between agent iterations.model
: (Optional) Change the AI model, e.g., if you want to switch from “gpt-4” to another model.schedule
: (Optional) Update the schedule details for the agent.max_iterations
: (Optional) Change the maximum iterations for the agent.user_timezone
: (Optional) Update the user’s timezone if needed.knowledge
: (Optional) Update or change the reference to the agent’s knowledge base.
4. AgentRun
AgentRun denotes the configuration attributes for starting a new agent run.
Attributes:
name
: A string representing the name of the run.goal
: (Optional) A list of specific goals for this run.instruction
: (Optional) A list of specific instructions for this run.
5. AgentRunFilter
This defines filters for selecting specific agent runs.
Attributes:
run_ids
: (Optional) A list of integers representing specific run IDs.run_status_filter
: (Optional) A string indicating a specific status to filter runs (e.g., ‘completed’, ‘paused’).
Now that you’ve understood how to work with SuperAGI Python Client Library, clone the repo though GitHub and get started: https://github.com/TransformerOptimus/SuperAGI-Python-Client