Note: The former Spring Boot example moduleThe pipeline example uses Spring AI Alibaba flow agents (SequentialAgent, ParallelAgent, LoopAgent) with AgentScopeAgent sub-agents and AgentScope DashScopeChatModel (agentscope-examples/multiagent-patterns/was removed during the 2.0 package refactor. Use the code snippets on this page as the reference implementation. For other runnable samples, seeagentscope-examples/documentation/.
Model). Each pipeline is built from ReActAgent-based AgentScopeAgents and invoked via PipelineService.
Prerequisites
- JDK 17+
- Maven 3.6+
- DashScope API key:
export AI_DASHSCOPE_API_KEY=your-keyor setspring.ai.dashscope.api-keyinapplication.yml
Model configuration
The example uses a singleModel bean (DashScopeChatModel) shared by all pipeline sub-agents:
1. SequentialAgent: natural language → SQL → score
Scenario: User describes a query in natural language. The pipeline (1) SQL Generator converts it to MySQL SQL, (2) SQL Rater scores how well the SQL matches user intent (0–1). Sub-agents run in sequence; each output feeds the next. Example input: “List all orders from the last 30 days with total amount greater than 500.”Implementation
- SQL Generator:
instruction("{input}"),outputKey("sql")— receives user input, writes generated SQL into state keysql. - SQL Rater:
instruction("... {sql} ... {input} ..."),outputKey("score")— receives previoussqland originalinput, writes score into state keyscore.
2. ParallelAgent: multi-angle research
Scenario: User provides a topic; the pipeline researches it from three angles in parallel: technology, finance/business, and market/industry. Results are merged into a single report (research_report).
Example input: “Research the current state of large language models.” (Demo uses “AI agents in enterprise software”.)
Implementation
- Each sub-agent has
instruction("Research the following topic: {input}.")and its ownoutputKey(tech_analysis,finance_analysis,market_analysis). - DefaultMergeStrategy merges sub-agent outputs into one; merged result is written to mergeOutputKey
research_report.
3. LoopAgent: SQL refinement until quality threshold
Scenario: Generate SQL from natural language and iteratively refine until the quality score exceeds 0.5. Each iteration runs an inner SequentialAgent: SQL Generator → SQL Rater. Loop continues until score > 0.5 or max iterations. Example input: “Find customers who placed more than 3 orders in 2024.”Implementation
LoopPipelineConfig builds the same SQL Generator and SQL Rater AgentScopeAgents as SequentialPipelineConfig (same prompts, instruction, outputKey). It then wraps them in a SequentialAgent and that in a LoopAgent with a condition-based loop strategy:
- LoopAgent wraps a single SequentialAgent (
sql_agent) that runs SQL Generator then SQL Rater each iteration. - loopStrategy:
LoopMode.condition(...)— receives the last turn’s messages, reads the last message (rater output), parses it as a number; returnstruewhen score > 0.5 to stop the loop.
Invoking pipelines: PipelineService
PipelineService is wired with the three agents and exposes runSequential, runParallel, and runLoop. Each method invokes the corresponding agent with a string input and returns a result record.
Service implementation (extract of how results are read from state):
Optional demo runner
Whenpipeline.runner.enabled=true, PipelineCommandRunner runs a demo for each pipeline on startup with sample inputs and logs the results:
Configuration
Related Documentation
- Routing - Classify and route to specialist agents
- MsgHub - Message broadcasting for multi-agent conversations
- Handoffs - State-driven routing and transfer between agents
- Multi-Agent Debate - Debate workflow pattern