Overview
In AgentScope AI, agents are autonomous entities that leverage advanced AI models to execute a sequence of actions for complex security and auditing tasks. Unlike one-off tools, these agents function as persistent assistants that can interact with external systems, invoke custom functions, and integrate with various APIs to provide continuous security insights and risk assessments. This document outlines how to create, configure, and interact with agents within the AgentScope AI ecosystem.
1. Creating and Configuring Agents
Agents in AgentScope AI are created using the Agent
class. Each agent is configured with a unique name, specific instructions, and the chosen language model provider. This configuration enables the agent to perform its designated security audit tasks effectively.
Example: Creating an Agent
Environment Setup
Ensure that all necessary environment variables, such as your API keys, are set in the .env
file:
Install the required package:
2. Registering the Agent
Once an agent is created, it must be registered with the AgentScope AI system to enable logging, access to configured tools, and integration with third-party services.
Example: Registering the Agent
3. Generating and Streaming Text
Agents can generate responses to user queries using the .generate()
method, which processes a series of messages and returns a text output. For more interactive applications, responses can also be streamed in real time.
Generating Text Example
Streaming Responses Example
4. Structured Output
Agents can return structured data by using a JSON Schema or a Zod schema. This ensures that the output is both predictable and type-safe.
Using JSON Schema
Using Zod Schema
5. Running Agents
AgentScope AI provides a CLI tool to run your agents behind an API. By default, the CLI looks for agents in the src/agents
directory.
Starting the Agent Server
This command starts the server, making your agents accessible at an endpoint such as http://localhost:4111/api/agents/securityAgent/generate
.
6. Interacting with Agents
You can interact with your agent through standard HTTP requests. For example, using curl
:
Last updated