fix: wire requester agent override for cron tools

This commit is contained in:
Peter Steinberger 2026-01-25 13:05:15 +00:00
parent 19e0b701cf
commit 11a6f6db2e
7 changed files with 98 additions and 5 deletions

View File

@ -157,4 +157,44 @@ describe("agents_list", () => {
const research = agents?.find((agent) => agent.id === "research"); const research = agents?.find((agent) => agent.id === "research");
expect(research?.configured).toBe(false); expect(research?.configured).toBe(false);
}); });
it("uses requesterAgentIdOverride when resolving allowlists", async () => {
configOverride = {
session: {
mainKey: "main",
scope: "per-sender",
},
agents: {
list: [
{
id: "cron-owner",
subagents: {
allowAgents: ["research"],
},
},
{
id: "research",
name: "Research",
},
],
},
};
const tool = createClawdbotTools({
agentSessionKey: "cron:job-1",
requesterAgentIdOverride: "cron-owner",
}).find((candidate) => candidate.name === "agents_list");
if (!tool) throw new Error("missing agents_list tool");
const result = await tool.execute("call5", {});
const agents = (
result.details as {
agents?: Array<{ id: string }>;
}
).agents;
expect(agents?.map((agent) => agent.id)).toEqual(["cron-owner", "research"]);
expect(result.details).toMatchObject({
requester: "cron-owner",
});
});
}); });

View File

@ -87,6 +87,52 @@ describe("clawdbot-tools: subagents", () => {
}); });
expect(childSessionKey?.startsWith("agent:research:subagent:")).toBe(true); expect(childSessionKey?.startsWith("agent:research:subagent:")).toBe(true);
}); });
it("sessions_spawn honors requesterAgentIdOverride for cron sessions", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
configOverride = {
session: {
mainKey: "main",
scope: "per-sender",
},
agents: {
list: [
{
id: "cron-owner",
subagents: {
allowAgents: ["research"],
},
},
],
},
};
callGatewayMock.mockImplementation(async (opts: unknown) => {
const request = opts as { method?: string; params?: unknown };
if (request.method === "agent") {
return { runId: "run-2", status: "accepted", acceptedAt: 5200 };
}
return {};
});
const tool = createClawdbotTools({
agentSessionKey: "cron:job-1",
requesterAgentIdOverride: "cron-owner",
agentChannel: "whatsapp",
}).find((candidate) => candidate.name === "sessions_spawn");
if (!tool) throw new Error("missing sessions_spawn tool");
const result = await tool.execute("call11", {
task: "do thing",
agentId: "research",
});
expect(result.details).toMatchObject({
status: "accepted",
runId: "run-2",
});
});
it("sessions_spawn forbids cross-agent spawning when not allowed", async () => { it("sessions_spawn forbids cross-agent spawning when not allowed", async () => {
resetSubagentRegistryForTests(); resetSubagentRegistryForTests();
callGatewayMock.mockReset(); callGatewayMock.mockReset();

View File

@ -150,10 +150,12 @@ export function createClawdbotTools(options?: {
config: options?.config, config: options?.config,
workspaceDir: options?.workspaceDir, workspaceDir: options?.workspaceDir,
agentDir: options?.agentDir, agentDir: options?.agentDir,
agentId: resolveSessionAgentId({ agentId:
sessionKey: options?.agentSessionKey, options?.requesterAgentIdOverride ??
config: options?.config, resolveSessionAgentId({
}), sessionKey: options?.agentSessionKey,
config: options?.config,
}),
sessionKey: options?.agentSessionKey, sessionKey: options?.agentSessionKey,
messageChannel: options?.agentChannel, messageChannel: options?.agentChannel,
agentAccountId: options?.agentAccountId, agentAccountId: options?.agentAccountId,

View File

@ -293,6 +293,7 @@ export function createClawdbotCodingTools(options?: {
agentGroupChannel: options?.groupChannel ?? null, agentGroupChannel: options?.groupChannel ?? null,
agentGroupSpace: options?.groupSpace ?? null, agentGroupSpace: options?.groupSpace ?? null,
agentDir: options?.agentDir, agentDir: options?.agentDir,
requesterAgentIdOverride: agentId,
sandboxRoot, sandboxRoot,
workspaceDir: options?.workspaceDir, workspaceDir: options?.workspaceDir,
sandboxed: !!sandbox, sandboxed: !!sandbox,

View File

@ -41,7 +41,9 @@ export function createAgentsListTool(opts?: {
}) })
: alias; : alias;
const requesterAgentId = normalizeAgentId( const requesterAgentId = normalizeAgentId(
opts?.requesterAgentIdOverride ?? parseAgentSessionKey(requesterInternalKey)?.agentId ?? DEFAULT_AGENT_ID, opts?.requesterAgentIdOverride ??
parseAgentSessionKey(requesterInternalKey)?.agentId ??
DEFAULT_AGENT_ID,
); );
const allowAgents = resolveAgentConfig(cfg, requesterAgentId)?.subagents?.allowAgents ?? []; const allowAgents = resolveAgentConfig(cfg, requesterAgentId)?.subagents?.allowAgents ?? [];

View File

@ -170,6 +170,7 @@ export async function handleInlineActions(params: {
agentAccountId: (ctx as { AccountId?: string }).AccountId, agentAccountId: (ctx as { AccountId?: string }).AccountId,
agentTo: ctx.OriginatingTo ?? ctx.To, agentTo: ctx.OriginatingTo ?? ctx.To,
agentThreadId: ctx.MessageThreadId ?? undefined, agentThreadId: ctx.MessageThreadId ?? undefined,
requesterAgentIdOverride: agentId,
agentDir, agentDir,
workspaceDir, workspaceDir,
config: cfg, config: cfg,

View File

@ -148,6 +148,7 @@ export async function handleToolsInvokeHttpRequest(
agentSessionKey: sessionKey, agentSessionKey: sessionKey,
agentChannel: messageChannel ?? undefined, agentChannel: messageChannel ?? undefined,
agentAccountId: accountId, agentAccountId: accountId,
requesterAgentIdOverride: agentId,
config: cfg, config: cfg,
pluginToolAllowlist: collectExplicitAllowlist([ pluginToolAllowlist: collectExplicitAllowlist([
profilePolicy, profilePolicy,