MCPcopy Create free account
hub / github.com/cloudflare/agents / onChatMessage

Method onChatMessage

examples/codemode/src/server.ts:67–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65 }
66
67 async onChatMessage() {
68 const workersai = createWorkersAI({ binding: this.env.AI });
69
70 const executor = new DynamicWorkerExecutor({
71 loader: this.env.LOADER
72 });
73
74 const mcpTools = this.mcp.getAITools();
75 const allTools = { ...this.tools, ...mcpTools };
76
77 const codemode = createCodeTool({
78 tools: allTools,
79 executor
80 });
81
82 const result = streamText({
83 model: workersai("@cf/moonshotai/kimi-k2.6", {
84 sessionAffinity: this.sessionAffinity
85 }),
86 system:
87 "You are a helpful project management assistant. " +
88 "You can create and manage projects, tasks, sprints, and comments using the codemode tool. " +
89 "When you need to perform operations, use the codemode tool to write JavaScript " +
90 "that calls the available functions on the `codemode` object.",
91 messages: pruneMessages({
92 messages: await convertToModelMessages(this.messages),
93 toolCalls: "before-last-2-messages",
94 reasoning: "before-last-message"
95 }),
96 tools: { codemode },
97 stopWhen: stepCountIs(10)
98 });
99
100 return result.toUIMessageStreamResponse();
101 }
102}
103
104export default {

Callers

nothing calls this directly

Calls 2

createCodeToolFunction · 0.90
getAIToolsMethod · 0.45

Tested by

no test coverage detected