Deployment in a High-code Manner #908
DavdGao
announced in
AgentScope Design Book
Replies: 1 comment
-
|
We're working on practical deployment examples covering multi-agent systems and custom agents. They'll be available soon! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, community! Thanks for your interest in and support for AgentScope.
We'd like to use this category "Design Book of AgentScope" as a space to share and discuss ideas about the design choices behind AgentScope. In this first post, we'll demonstrate how to deploy agents using a high-code approach, with a focus on:
We'll use a routing agent as our example—a typical multi-agent system that routes user requests to different sub-agents based on request content, to illustrate multi-agent deployment in high-code manner.
Key Questions to Ask
Before diving into deployment, it's helpful to think through a few key questions about your system:
Q: How will you handle incoming requests? (e.g., by thread, by process, by async task, etc.)
This will affect the design of your agent system. For example, in Flask, each request is handled in a new thread, with both the server and requests running in a single Python process. In such cases, thread-safety becomes critical—you need to be careful about using global variables, as different requests may interfere with each other.
Q: Is your application multi-tenant or single-tenant?
This determines how you'll manage and isolate state across different users. Don't worry though—AgentScope provides application-level state management, which we'll discuss later.
Q: How will you send messages to the frontend?
This decides what your endpoint function should return. If messages need to be streamed back through the request endpoint, your endpoint should return a generator.
Alternatively, you can send messages directly to the frontend or a pub/sub system (like Redis). In this case, the endpoint function can simply return a basic response, like "200 OK".
Q: How will you expose agents to users?
This depends on your user interaction design. Here are two approaches with their trade-offs:
This choice will determine how you handle sub-agent messages:
create_worker.Putting It into Practice
Once you've thought through these questions, let's focus on the agent application itself rather than infrastructure concerns like concurrency or latency.
We'll cover two key aspects:
For illustration purposes, we'll use Quark as our web framework in the examples. The streaming approach (where endpoints return generators) will be covered in the Frontend Display section.
State Management
Understanding State in AgentScope
A common misconception is that only memory constitutes an agent's state. That's not necessarily true. In AgentScope, a
PlanNotebookinstance, aToolkitinstance, or even custom attributes can all be part of the state. Here are some examples:Example 1: Planning state
AgentScope's planning capability, supported by
PlanNotebook, allows agents to request additional information from users during execution. This means plan execution spans multiple user requests, requiring us to maintain the execution state across them.Example 2: Toolkit state
When using group-wise management or meta tools in AgentScope, the toolkit tracks activated tool groups, which must also persist across requests.
Example 3: Custom attributes
Imagine you want to surprise users on their 100th conversation. You'd add a counter to track conversations and trigger the surprise at 100:
This counter is clearly part of the state that needs to persist.
These examples illustrate why AgentScope provides the
StateModuleclass for state management. It handles state in two ways:StateModuleinstance, it's automatically included in the parent's state. For example, if aReActAgentinstance has aplan_notebookattribute that is aPlanNotebookinstance (both areStateModulesubclasses), the notebook's state is automatically saved/loaded with the agent.register_state()to include them in the state, optionally with custom save/load logic.This mechanism enables AgentScope to seamlessly support custom agent implementations. As long as your custom agent inherits from
AgentBaseorReActAgentBase, its state will be automatically managed without extra effort from developers.Using Session Modules
Here's how to manage state with session modules:
In practice, developer can create their own session management class by inheriting from
SessionBase, to customize how session states are saved and loaded. For example, loading/saving states from a cloud database.Frontend Displaying
As mentioned earlier, there are two approaches to displaying sub-agent messages.
Approach 1: Expose sub-agents to users
When you want users to see sub-agents in action, you can stream their messages directly to the frontend. This approach makes the multi-agent workflow transparent to users.
If you need to stream all messages from your endpoint function, AgentScope provides the
stream_printing_messagespipeline to handle this. It collects printing messages from multiple agents and yields them in order, making it easy to implement streaming responses.The key idea is to use a shared
asyncio.Queueto collect messages from both the main agent and any dynamically created sub-agents. Here's how it works:Step 1: Create sub-agents with message streaming enabled
In your tool function, configure sub-agents to send their messages to the shared queue:
Step 2: Set up the endpoint with streaming
In your endpoint function, create the shared queue and use
stream_printing_messagesto stream all messages:The beauty of this approach is that even though only the main agent is passed to stream_printing_messages, messages from all sub-agents are automatically captured through the shared queue.
Approach 2: Hide Sub-Agents from Users
Another way is to hide sub-agents from users, treating their printing messages as tool results. This keeps the user interface clean and focused on the main agent.
In this case, we first prepare a function to convert and compress sub-agent messages into text blocks in the tool result
of the main agent.
Note we need to shorten tool use and result messages to avoid bloating the main agent's context.
After that, we can implement the tool function to create a worker agent and yield streaming tool responses:
With this approach, users only interact with the main agent, while sub-agent activities appear as concise tool execution updates.
Wrapping Up
We've walked through the key considerations for deploying multi-agent systems with AgentScope: from clarifying your requirements upfront, to managing state across custom agents, to choosing how to present agent activities to users.
These design choices don't have universal "right" answers—they depend on your specific use case and user needs. AgentScope aims to provide the flexibility to support different approaches while handling the complex parts (like state management and message streaming) for you.
We'd love to hear about your experiences deploying agent systems. What challenges have you encountered? What design decisions worked well for your use case? Feel free to share your thoughts and questions in the comments below.
Happy building! 🚀
Beta Was this translation helpful? Give feedback.
All reactions