Skip to content

WIP(core): support custom role for tool result - #870

Draft
li-yechao wants to merge 1 commit into
mainfrom
fix/custom-tool-result-role
Draft

WIP(core): support custom role for tool result#870
li-yechao wants to merge 1 commit into
mainfrom
fix/custom-tool-result-role

Conversation

@li-yechao

@li-yechao li-yechao commented Jan 4, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Major Changes

Screenshots

Test Plan

Checklist

  • This change requires documentation updates, and I have updated the relevant documentation. If the documentation has not been updated, please create a documentation update issue and link it here
  • The changes are already covered by tests, and I have adjusted the test coverage for the changed parts
  • The newly added code logic is also covered by tests
  • This change adds dependencies, and they are placed in dependencies and devDependencies
  • This change includes adding or updating npm dependencies, and it does not result in multiple versions of the same dependency [check the diff of pnpm-lock.yaml]

Summary by AIGNE

Release Notes

New Feature:

  • Added roleInToolUse configuration option to agent settings, allowing tools to be executed with custom user roles
  • Enhanced agent session handling to support optional message parameters for improved flexibility

Refactor:

  • Updated agent configuration schema to support the new role-based tool execution feature
  • Modified agent session message handling to accommodate conditional message creation

This update enables more flexible tool interaction patterns by allowing agents to customize how tool results are presented and processed within conversations.

@github-actions

github-actions Bot commented Jan 4, 2026

Copy link
Copy Markdown

Image description AIGNE CodeSmith

Walkthrough

This change implements a new roleInToolUse feature that allows agents to customize their role behavior during tool interactions. The feature adds an optional property that can be set to "user" to modify how tool results are handled. When enabled, the agent immediately ends its message after a tool call and starts a new user message with the tool result, changing the conversation flow pattern.

Changes

Files Summary
packages/core/src/agents/agent.ts, packages/core/src/loader/agent-yaml.ts Added roleInToolUse property to agent configuration interfaces and classes, with Zod schema validation supporting undefined or "user" values
packages/core/src/agents/ai-agent.ts Implemented conditional logic to handle tools with roleInToolUse === "user" by immediately ending agent messages and starting user messages with tool results
packages/core/src/prompt/agent-session.ts Modified startMessage and endMessage methods to accept optional message parameters, updating validation and initialization logic accordingly

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description AIGNE CodeSmith

Commits Files that changed from the base of the PR and between 9c621e7 and cee9f6a commits.
Files selected (4)
  • packages/core/src/agents/agent.ts (4)
  • packages/core/src/agents/ai-agent.ts (3)
  • packages/core/src/loader/agent-yaml.ts (3)
  • packages/core/src/prompt/agent-session.ts (2)
Review comments generated (16)
  • Review: 1
  • LGTM: 15

提示

Image description AIGNE CodeSmith (@codesmith) 聊天

  • 回复此机器人留下的审查评论以提出后续问题。审查评论是对差异或文件的评论。
  • 通过在回复中标记 @codesmith 邀请机器人加入审查评论链。

代码建议

  • 机器人可能会提出代码建议,但在提交前请仔细审查它们,因为行号范围可能会不对齐。
  • 你可以编辑机器人做出的评论,并在建议稍有偏差时手动调整。

暂停增量审查

  • 在 PR 描述中的任何位置添加 @codesmith: ignore 以暂停机器人的进一步审查。

if (toolCalls.length === 1 && firstToolCall) {
const tool = toolsMap.get(firstToolCall.function.name);
if (tool?.roleInToolUse === "user") {
await session.endMessage({}, { role: "agent", toolCalls }, options);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description AIGNE CodeSmith

There's a parameter mismatch in the endMessage call. The method signature expects (result, message, options) but you're passing ({}, message, options).

-            await session.endMessage({}, { role: "agent", toolCalls }, options);
+            await session.endMessage({ role: "agent", toolCalls }, undefined, options);

@li-yechao li-yechao changed the title fix(core): support custom role for tool result WIP(core): support custom role for tool result Jan 4, 2026
@li-yechao
li-yechao marked this pull request as draft January 5, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant