Skip to content

Commit e0e3527

Browse files
committed
fix(agent): 修正 ToolsExample 中 ToolContext 错误的 key,改用 ToolContextConstants 常量
1 parent e1b1482 commit e0e3527

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • examples/documentation/src/main/java/com/alibaba/cloud/ai/examples/documentation/framework/tutorials

examples/documentation/src/main/java/com/alibaba/cloud/ai/examples/documentation/framework/tutorials/ToolsExample.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
import java.util.function.BiFunction;
4545
import java.util.function.Function;
4646

47+
import static com.alibaba.cloud.ai.graph.agent.tools.ToolContextConstants.AGENT_CONFIG_CONTEXT_KEY;
48+
import static com.alibaba.cloud.ai.graph.agent.tools.ToolContextConstants.AGENT_STATE_CONTEXT_KEY;
49+
4750
/**
4851
* Tools Tutorial - 完整代码示例
4952
* 展示如何创建和使用Tools让Agent与外部系统交互
@@ -721,8 +724,8 @@ public static class ConversationSummaryTool implements BiFunction<String, ToolCo
721724

722725
@Override
723726
public String apply(String input, ToolContext toolContext) {
724-
OverAllState state = (OverAllState) toolContext.getContext().get("state");
725-
RunnableConfig config = (RunnableConfig) toolContext.getContext().get("config");
727+
OverAllState state = (OverAllState) toolContext.getContext().get(AGENT_STATE_CONTEXT_KEY);
728+
RunnableConfig config = (RunnableConfig) toolContext.getContext().get(AGENT_CONFIG_CONTEXT_KEY);
726729

727730
// 从state中获取消息
728731
Optional<Object> messagesOpt = state.value("messages");
@@ -775,7 +778,7 @@ public static class AccountInfoTool implements BiFunction<String, ToolContext, S
775778

776779
@Override
777780
public String apply(String query, ToolContext toolContext) {
778-
RunnableConfig config = (RunnableConfig) toolContext.getContext().get("config");
781+
RunnableConfig config = (RunnableConfig) toolContext.getContext().get(AGENT_CONFIG_CONTEXT_KEY);
779782
String userId = (String) config.metadata("user_id").orElse(null);
780783

781784
if (userId == null) {

0 commit comments

Comments
 (0)