Skip to content

Commit 4c0da4b

Browse files
authored
add create_pr tool to routing multi-agent example (#4824)
feat(examples): add create_pr tool to routing multi-agent example Add a create_pr tool to both simple and graph routing variants, allowing the GitHub agent to draft pull requests. Update prompts and README to document the new capability.
1 parent 84ca19a commit 4c0da4b

6 files changed

Lines changed: 24 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ modified_mcp_config.json
5959
**/spans.json
6060

6161
.checkstyle
62+
model-config.yaml

examples/multiagent-patterns/routing/src/main/java/com/alibaba/cloud/ai/examples/multiagents/routing/graph/RoutingGraphConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
public class RoutingGraphConfig {
5050

5151
private static final String GITHUB_PROMPT = """
52-
You are a GitHub expert. Answer questions about code, API references, and implementation \
53-
details by searching repositories, issues, and pull requests.
52+
You are a GitHub expert. Answer questions about code, API references, implementation details, and pull request operations by searching repositories, issues, and pull requests.
53+
You may use `create_pr` to draft or summarize a pull request when appropriate.
5454
Please respond to the following request: {github_input}
5555
""";
5656

examples/multiagent-patterns/routing/src/main/java/com/alibaba/cloud/ai/examples/multiagents/routing/graph/tools/GitHubStubTools.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@ public String searchIssues(@ToolParam(description = "Search query") String query
4343
public String searchPrs(@ToolParam(description = "Search query") String query) {
4444
return "PR #156 added JWT authentication, PR #178 updated OAuth scopes";
4545
}
46+
47+
@Tool(name = "create_pr", description = "Create a pull request on GitHub.")
48+
public String createPullRequest(
49+
@ToolParam(description = "Branch or commit to merge from") String sourceBranch,
50+
@ToolParam(description = "Target branch for the pull request") String targetBranch,
51+
@ToolParam(description = "Title of the pull request") String title,
52+
@ToolParam(description = "Pull request description") String body) {
53+
return String.format("Created PR from %s into %s: %s\n%s", sourceBranch, targetBranch, title, body);
54+
}
4655
}

examples/multiagent-patterns/routing/src/main/java/com/alibaba/cloud/ai/examples/multiagents/routing/simple/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This example implements the **routing** multi-agent pattern with Spring AI Aliba
77
- **LlmRoutingAgent**
88
The core routing component. An LLM analyzes the query and routes to one or more specialist agents with targeted sub-queries. Each agent receives its sub-question via the `{agentName_input}` placeholder in its instruction. Selected agents run in parallel via the framework's graph-based parallel conditional edges.
99
- **Specialist agents**
10-
- **GitHub agent**: Tools `search_code`, `search_issues`, `search_prs`; answers about code, API references, implementation details.
10+
- **GitHub agent**: Tools `search_code`, `search_issues`, `search_prs`, `create_pr`; answers about code, API references, implementation details.
1111
- **Notion agent**: Tools `search_notion`, `get_page`; answers about internal docs, processes, wikis.
1212
- **Slack agent**: Tools `search_slack`, `get_thread`; answers from team discussions and threads.
1313

examples/multiagent-patterns/routing/src/main/java/com/alibaba/cloud/ai/examples/multiagents/routing/simple/RoutingConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public class RoutingConfig {
4141
* {@link LlmRoutingAgent.LlmRoutingAgentBuilder#instruction(String)} when building the router agent.
4242
*/
4343
private static final String GITHUB_PROMPT = """
44-
You are a GitHub expert. Answer questions about code, API references, and implementation \
45-
details by searching repositories, issues, and pull requests.
44+
You are a GitHub expert. Answer questions about code, API references, implementation details, and pull request operations by searching repositories, issues, and pull requests.
45+
You may use `create_pr` to draft or summarize a pull request when appropriate.
4646
Please respond to the following request: {github_input}
4747
""";
4848

examples/multiagent-patterns/routing/src/main/java/com/alibaba/cloud/ai/examples/multiagents/routing/simple/tools/GitHubStubTools.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@ public String searchIssues(@ToolParam(description = "Search query") String query
4343
public String searchPrs(@ToolParam(description = "Search query") String query) {
4444
return "PR #156 added JWT authentication, PR #178 updated OAuth scopes";
4545
}
46+
47+
@Tool(name = "create_pr", description = "Create a pull request on GitHub.")
48+
public String createPullRequest(
49+
@ToolParam(description = "Branch or commit to merge from") String sourceBranch,
50+
@ToolParam(description = "Target branch for the pull request") String targetBranch,
51+
@ToolParam(description = "Title of the pull request") String title,
52+
@ToolParam(description = "Pull request description") String body) {
53+
return String.format("Created PR from %s into %s: %s\n%s", sourceBranch, targetBranch, title, body);
54+
}
4655
}

0 commit comments

Comments
 (0)