Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/agent-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ so the agent does not rediscover, convert, or screenshot the same file before fi

Composio REST tool discovery and execution responses are byte-bounded before
parsing, then projected into bounded, valid JSON before entering model context.
The durable tool executor binds each checkpointed tool-call identity into the
request context before Mastra execution. Composio quota charging derives its
idempotency key from that explicit context value instead of relying on
compatibility-layer execution fields that Mastra does not preserve.
Toolkit names use the shared open-slug contract from
`@cheatcode/types/integrations` across API, context, and tool boundaries.
Discovery first uses Composio's full-text query. Because that query can return zero for an
Expand Down
1 change: 1 addition & 0 deletions packages/agent-core/src/mastra/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const CONTEXT = {
runIntent: "runIntent",
selectedSkill: "selectedSkill",
selectedTool: "selectedTool",
toolCallId: "toolCallId",
userSkillCreator: "userSkillCreator",
userSkillLoader: "userSkillLoader",
userSkills: "userSkills",
Expand Down
5 changes: 5 additions & 0 deletions packages/agent-core/src/mastra/durable-agent-step.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { RequestContext } from "@mastra/core/request-context";
import { type JSONValue, type ModelMessage, modelMessageSchema } from "ai";
import { z } from "zod";
import { CONTEXT } from "./context";
import { mastra } from "./index";
import { cheatcodeTools } from "./tool-defs/tool-set";

Expand Down Expand Up @@ -122,6 +123,10 @@ export async function executeGeneralAgentTool(
if (!tool?.execute) {
throw new Error(`Unknown or non-executable agent tool: ${options.toolName}`);
}
// Mastra's execution wrapper does not preserve arbitrary top-level compatibility
// fields. Bind the durable call identity explicitly so request-scoped tools can
// derive stable idempotency keys without serializing them into model arguments.
options.requestContext.set(CONTEXT.toolCallId, options.toolCallId);
return tool.execute(options.input, {
...(options.abortSignal ? { abortSignal: options.abortSignal } : {}),
// Repository tools use requestContext for their runtime dependencies and
Expand Down
4 changes: 2 additions & 2 deletions packages/agent-core/src/mastra/tool-defs/composio-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ export const mastraComposioExecute = createTool({
});

function composioQuotaEventId(context: unknown): string {
const record = typeof context === "object" && context !== null ? context : {};
const candidate = (record as Record<string, unknown>)["toolCallId"];
const requestContext = requestContextFromToolContext(context);
const candidate = requestContext.get(CONTEXT.toolCallId);
if (typeof candidate !== "string" || candidate.length === 0 || candidate.length > 180) {
throw new Error("Composio execution requires a bounded tool-call id.");
}
Expand Down