fix: let agent finish tool-heavy chat tasks
This commit is contained in:
1 parent
46dea81631
commit
3a0e0fb0b6
4 files changed
+53
-21
No files matched your search
+31
-21
@@ -94,27 +94,10 @@ export async function runGooseAgent(
|
|||||||
);
|
);
|
||||||
const containerName = `ghbot-agent-${randomBytes(12).toString("hex")}`;
|
const containerName = `ghbot-agent-${randomBytes(12).toString("hex")}`;
|
||||||
const hostGooseBinary = await resolveHostGooseBinary();
|
const hostGooseBinary = await resolveHostGooseBinary();
|
||||||
const containerEnv = {
|
const containerEnv = buildGooseAgentEnvironment({
|
||||||
HOME: "/tmp/goose-home",
|
apiToken: proxy.token,
|
||||||
XDG_CONFIG_HOME: "/tmp/goose-home/config",
|
proxyPort: proxy.port
|
||||||
XDG_DATA_HOME: "/tmp/goose-home/data",
|
});
|
||||||
XDG_STATE_HOME: "/tmp/goose-home/state",
|
|
||||||
XDG_CACHE_HOME: "/tmp/goose-home/cache",
|
|
||||||
GOOSE_PROVIDER: "openai",
|
|
||||||
GOOSE_MODEL: config.gooseModel,
|
|
||||||
GOOSE_MODE: "auto",
|
|
||||||
GOOSE_DISABLE_KEYRING: "true",
|
|
||||||
GOOSE_DISABLE_SESSION_NAMING: "true",
|
|
||||||
GOOSE_TELEMETRY_ENABLED: "false",
|
|
||||||
GOOSE_MAX_TURNS: "25",
|
|
||||||
CONTEXT_FILE_NAMES: "[]",
|
|
||||||
OPENAI_API_KEY: proxy.token,
|
|
||||||
OPENAI_BASE_URL: `http://host.docker.internal:${proxy.port}/v1`,
|
|
||||||
OPENAI_TIMEOUT: "600",
|
|
||||||
...(config.gooseThinkingEffort
|
|
||||||
? { GOOSE_THINKING_EFFORT: config.gooseThinkingEffort }
|
|
||||||
: {})
|
|
||||||
};
|
|
||||||
const args = buildGooseAgentDockerArgs({
|
const args = buildGooseAgentDockerArgs({
|
||||||
containerName,
|
containerName,
|
||||||
realWorkingDirectory,
|
realWorkingDirectory,
|
||||||
@@ -145,6 +128,33 @@ export async function runGooseAgent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function buildGooseAgentEnvironment(params: {
|
||||||
|
apiToken: string;
|
||||||
|
proxyPort: number;
|
||||||
|
}): Record<string, string> {
|
||||||
|
return {
|
||||||
|
HOME: "/tmp/goose-home",
|
||||||
|
XDG_CONFIG_HOME: "/tmp/goose-home/config",
|
||||||
|
XDG_DATA_HOME: "/tmp/goose-home/data",
|
||||||
|
XDG_STATE_HOME: "/tmp/goose-home/state",
|
||||||
|
XDG_CACHE_HOME: "/tmp/goose-home/cache",
|
||||||
|
GOOSE_PROVIDER: "openai",
|
||||||
|
GOOSE_MODEL: config.gooseModel,
|
||||||
|
GOOSE_MODE: "auto",
|
||||||
|
GOOSE_DISABLE_KEYRING: "true",
|
||||||
|
GOOSE_DISABLE_SESSION_NAMING: "true",
|
||||||
|
GOOSE_TELEMETRY_ENABLED: "false",
|
||||||
|
GOOSE_MAX_TURNS: "50",
|
||||||
|
CONTEXT_FILE_NAMES: "[]",
|
||||||
|
OPENAI_API_KEY: params.apiToken,
|
||||||
|
OPENAI_BASE_URL: `http://host.docker.internal:${params.proxyPort}/v1`,
|
||||||
|
OPENAI_TIMEOUT: "600",
|
||||||
|
...(config.gooseThinkingEffort
|
||||||
|
? { GOOSE_THINKING_EFFORT: config.gooseThinkingEffort }
|
||||||
|
: {})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function buildGooseAgentDockerArgs(params: {
|
export function buildGooseAgentDockerArgs(params: {
|
||||||
containerName: string;
|
containerName: string;
|
||||||
realWorkingDirectory: string;
|
realWorkingDirectory: string;
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ function buildChatPrompt(input: {
|
|||||||
chatReplyLanguageInstruction(input.commentBody),
|
chatReplyLanguageInstruction(input.commentBody),
|
||||||
"Use the supplied current PR metadata and patch as context. When the question is related to repository code, inspect the checked-out current PR source before answering.",
|
"Use the supplied current PR metadata and patch as context. When the question is related to repository code, inspect the checked-out current PR source before answering.",
|
||||||
"You have full goose Developer tool permission inside a disposable isolated container. You may read and edit the temporary workspace, execute commands and tests, install dependencies, and use the network when useful to answer accurately.",
|
"You have full goose Developer tool permission inside a disposable isolated container. You may read and edit the temporary workspace, execute commands and tests, install dependencies, and use the network when useful to answer accurately.",
|
||||||
|
chatToolBudgetInstruction(),
|
||||||
"Report commands or tests as completed only when their tool results show they actually completed. Workspace edits are temporary and cannot be committed or pushed.",
|
"Report commands or tests as completed only when their tool results show they actually completed. Workspace edits are temporary and cannot be committed or pushed.",
|
||||||
...(input.repositoryKnowledgeEnabled
|
...(input.repositoryKnowledgeEnabled
|
||||||
? [
|
? [
|
||||||
@@ -291,6 +292,10 @@ function buildChatPrompt(input: {
|
|||||||
].join("\n");
|
].join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function chatToolBudgetInstruction(): string {
|
||||||
|
return "Manage the finite tool-action budget autonomously. Do not ask the user whether to continue. Before the budget is exhausted, stop optional exploration, finish any authorized knowledge-file update, and return the best complete final answer with any remaining limitations stated clearly.";
|
||||||
|
}
|
||||||
|
|
||||||
function escapeRegExp(value: string): string {
|
function escapeRegExp(value: string): string {
|
||||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import path from "node:path";
|
|||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import {
|
import {
|
||||||
buildChatRequesterContext,
|
buildChatRequesterContext,
|
||||||
|
chatToolBudgetInstruction,
|
||||||
chatReplyLanguageInstruction,
|
chatReplyLanguageInstruction,
|
||||||
containsBotMention,
|
containsBotMention,
|
||||||
createRepositorySnapshot,
|
createRepositorySnapshot,
|
||||||
@@ -50,6 +51,11 @@ test("PR chat replies in the language of the latest user comment", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("PR chat must finish within its tool budget without asking to continue", () => {
|
||||||
|
assert.match(chatToolBudgetInstruction(), /Do not ask the user whether to continue/);
|
||||||
|
assert.match(chatToolBudgetInstruction(), /return the best complete final answer/);
|
||||||
|
});
|
||||||
|
|
||||||
test("PR chat recognizes @bot and the configured bot login", () => {
|
test("PR chat recognizes @bot and the configured bot login", () => {
|
||||||
assert.equal(containsBotMention("@bot can this merge?", "github-actions[bot]"), true);
|
assert.equal(containsBotMention("@bot can this merge?", "github-actions[bot]"), true);
|
||||||
assert.equal(containsBotMention("Could @github-actions explain this?", "github-actions[bot]"), true);
|
assert.equal(containsBotMention("Could @github-actions explain this?", "github-actions[bot]"), true);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
|||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import {
|
import {
|
||||||
buildGooseAgentDockerArgs,
|
buildGooseAgentDockerArgs,
|
||||||
|
buildGooseAgentEnvironment,
|
||||||
buildWorkspacePermissionDockerArgs,
|
buildWorkspacePermissionDockerArgs,
|
||||||
extractGooseFinalText
|
extractGooseFinalText
|
||||||
} from "../src/ai/gooseCli.js";
|
} from "../src/ai/gooseCli.js";
|
||||||
@@ -37,6 +38,16 @@ test("goose agent can fall back to installing inside the container", () => {
|
|||||||
assert.match(args[args.indexOf("-lc") + 1]!, /GOOSE_VERSION="v1\.46\.0"/);
|
assert.match(args[args.indexOf("-lc") + 1]!, /GOOSE_VERSION="v1\.46\.0"/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("goose repository agent has enough turns to finish tool-heavy tasks", () => {
|
||||||
|
const environment = buildGooseAgentEnvironment({
|
||||||
|
apiToken: "one-run-token",
|
||||||
|
proxyPort: 43123
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(environment.GOOSE_MAX_TURNS, "50");
|
||||||
|
assert.equal(environment.OPENAI_BASE_URL, "http://host.docker.internal:43123/v1");
|
||||||
|
});
|
||||||
|
|
||||||
test("goose agent restores host-cleanable permissions for root-owned workspace entries", () => {
|
test("goose agent restores host-cleanable permissions for root-owned workspace entries", () => {
|
||||||
const args = buildWorkspacePermissionDockerArgs("/tmp/worktree");
|
const args = buildWorkspacePermissionDockerArgs("/tmp/worktree");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user