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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class ConversationComponent implements OnInit, OnDestroy, AfterViewInit {
const id = this.llmId();
return !!id && (
id.startsWith('openai:o') ||
id === 'openai:gpt-5' ||
id.includes('claude-3-7') ||
id.includes('sonnet-4') ||
id.includes('opus-4') ||
Expand Down
2 changes: 0 additions & 2 deletions shared/user/user.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Chat } from '#shared/chat/chat.model';

export interface LLMServicesConfig {
vertexProjectId?: string;
vertexRegion?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/agent/agentContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import sinon from 'sinon';
import { LlmFunctionsImpl } from '#agent/LlmFunctionsImpl';
import { createContext } from '#agent/agentContextLocalStorage';
import { deserializeContext, serializeContext } from '#agent/agentSerialization';
import type { RunAgentConfig } from '#agent/autonomous/autonomousAgentRunner';
import { appContext } from '#app/applicationContext';
import { LlmTools } from '#functions/llmTools';
import { openaiGPT5 } from '#llm/services/openai';
import type { AgentContext } from '#shared/agent/agent.model';
import { functionRegistry } from '../functionRegistry';
import type { RunAgentConfig } from './autonomous/runAgentTypes';

describe('agentContext', () => {
before(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/agentContextLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AsyncLocalStorage } from 'node:async_hooks';
import { randomUUID } from 'node:crypto';
import { LlmFunctionsImpl } from '#agent/LlmFunctionsImpl';
import { ConsoleCompletedHandler } from '#agent/autonomous/agentCompletion';
import type { RunAgentConfig, RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import { FileSystemService } from '#functions/storage/fileSystemService';
import { logger } from '#o11y/logger';
import type { AgentContext, AgentLLMs } from '#shared/agent/agent.model';
import type { IFileSystemService } from '#shared/files/fileSystemService';
import { currentUser } from '#user/userContext';
import type { RunAgentConfig, RunWorkflowConfig } from './autonomous/runAgentTypes';

let _fileSystemOverride: IFileSystemService | null = null;

Expand Down
46 changes: 2 additions & 44 deletions src/agent/autonomous/autonomousAgentRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { randomUUID } from 'node:crypto';
import type { LlmFunctionsImpl } from '#agent/LlmFunctionsImpl';
import { createContext } from '#agent/agentContextLocalStorage';
import { runCodeGenAgent } from '#agent/autonomous/codegen/codegenAutonomousAgent';
import { AGENT_REQUEST_FEEDBACK } from '#agent/autonomous/functions/agentFeedback';
Expand All @@ -10,57 +9,16 @@ import { FUNC_SEP } from '#functionSchema/functions';
import { Git } from '#functions/scm/git';
import { GitHub } from '#functions/scm/github';
import { logger } from '#o11y/logger';
import type { AgentCompleted, AgentContext, AgentLLMs, AgentType } from '#shared/agent/agent.model';
import type { AgentContext } from '#shared/agent/agent.model';
import type { FunctionCallResult } from '#shared/llm/llm.model';
import type { User } from '#shared/user/user.model';
import { runAsUser } from '#user/userContext';
import { errorToString } from '#utils/errors';
import { CDATA_END, CDATA_START } from '#utils/xml-utils';
import { RunAgentConfig } from './runAgentTypes';

export const SUPERVISOR_RESUMED_FUNCTION_NAME: string = `Supervisor${FUNC_SEP}Resumed`;
export const SUPERVISOR_CANCELLED_FUNCTION_NAME: string = `Supervisor${FUNC_SEP}Cancelled`;

export type RunWorkflowConfig = Omit<RunAgentConfig, 'type' | 'functions'> & Partial<Pick<RunAgentConfig, 'functions'>>;

/**
* Configuration for running an autonomous agent
*/
export interface RunAgentConfig {
/** The user who created the agent. Uses currentUser() if not provided */
user?: User;
/** The parent agentId */
parentAgentId?: string;
codeTaskId?: string;
/** The name of this agent */
agentName: string;
/** Autonomous or workflow */
type: AgentType;
/** For autonomous agents either xml or codegen. For workflow agents it identifies the workflow type */
subtype: string;
/** The function classes the agent has available to call */
functions: LlmFunctionsImpl | Array<new () => any>;
/** Handler for when the agent finishes executing. Defaults to console output */
completedHandler?: AgentCompleted;
/** The user prompt */
initialPrompt: string;
/** The agent system prompt */
systemPrompt?: string;
/** Settings for requiring a human-in-the-loop */
humanInLoop?: { budget?: number; count?: number; functionErrorCount?: number };
/** The default LLMs available to use */
llms?: AgentLLMs;
/** The agent to resume */
resumeAgentId?: string;
/** The base path of the context FileSystem. Defaults to the process working directory */
fileSystemPath?: string;
/** Use shared repository location instead of agent-specific directory. Defaults to true. */
useSharedRepos?: boolean;
/** If running in a container, the ID of the container */
containerId?: string;
/** Additional details for the agent */
metadata?: Record<string, any>;
}

/**
* The reference to a running agent
*/
Expand Down
10 changes: 2 additions & 8 deletions src/agent/autonomous/codegen/codeGenAgentRunner.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { LlmFunctionsImpl } from '#agent/LlmFunctionsImpl';
import {
type RunAgentConfig,
SUPERVISOR_CANCELLED_FUNCTION_NAME,
cancelAgent,
provideFeedback,
runAgentAndWait,
startAgent,
} from '#agent/autonomous/autonomousAgentRunner';
import { SUPERVISOR_CANCELLED_FUNCTION_NAME, cancelAgent, provideFeedback, runAgentAndWait, startAgent } from '#agent/autonomous/autonomousAgentRunner';
import { convertTypeScriptToPython } from '#agent/autonomous/codegen/pythonCodeGenUtils';
import { AGENT_REQUEST_FEEDBACK, AgentFeedback } from '#agent/autonomous/functions/agentFeedback';
import { AGENT_COMPLETED_NAME, AGENT_MEMORY } from '#agent/autonomous/functions/agentFunctions';
Expand All @@ -22,6 +15,7 @@ import { lastText } from '#shared/llm/llm.model';
import { setupConditionalLoggerOutput } from '#test/testUtils';
import { sleep } from '#utils/async-utils';
import { agentContextStorage } from '../../agentContextLocalStorage';
import { type RunAgentConfig } from '../runAgentTypes';

const PY_AGENT_COMPLETED = (note: string) => `await ${AGENT_COMPLETED_NAME}("${note}")`;
const PY_AGENT_REQUEST_FEEDBACK = (feedback: string) => `await ${AGENT_REQUEST_FEEDBACK}("${feedback}")`;
Expand Down
43 changes: 43 additions & 0 deletions src/agent/autonomous/runAgentTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { AgentCompleted, AgentLLMs, AgentType, LlmFunctions } from '#shared/agent/agent.model';
import type { User } from '#shared/user/user.model';

export type RunWorkflowConfig = Omit<RunAgentConfig, 'type' | 'functions'> & Partial<Pick<RunAgentConfig, 'functions'>>;

/**
* Configuration for running an autonomous agent
*/
export interface RunAgentConfig {
/** The user who created the agent. Uses currentUser() if not provided */
user?: User;
/** The parent agentId */
parentAgentId?: string;
codeTaskId?: string;
/** The name of this agent */
agentName: string;
/** Autonomous or workflow */
type: AgentType;
/** For autonomous agents either xml or codegen. For workflow agents it identifies the workflow type */
subtype: string;
/** The function classes the agent has available to call */
functions: LlmFunctions | Array<new () => any>;
/** Handler for when the agent finishes executing. Defaults to console output */
completedHandler?: AgentCompleted;
/** The user prompt */
initialPrompt: string;
/** The agent system prompt */
systemPrompt?: string;
/** Settings for requiring a human-in-the-loop */
humanInLoop?: { budget?: number; count?: number; functionErrorCount?: number };
/** The default LLMs available to use */
llms?: AgentLLMs;
/** The agent to resume */
resumeAgentId?: string;
/** The base path of the context FileSystem. Defaults to the process working directory */
fileSystemPath?: string;
/** Use shared repository location instead of agent-specific directory. Defaults to true. */
useSharedRepos?: boolean;
/** If running in a container, the ID of the container */
containerId?: string;
/** Additional details for the agent */
metadata?: Record<string, any>;
}
10 changes: 2 additions & 8 deletions src/agent/autonomous/xml/xmlAutonomousAgent.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { LlmFunctionsImpl } from '#agent/LlmFunctionsImpl';
import {
type RunAgentConfig,
SUPERVISOR_CANCELLED_FUNCTION_NAME,
cancelAgent,
provideFeedback,
runAgentAndWait,
startAgent,
} from '#agent/autonomous/autonomousAgentRunner';
import { SUPERVISOR_CANCELLED_FUNCTION_NAME, cancelAgent, provideFeedback, runAgentAndWait, startAgent } from '#agent/autonomous/autonomousAgentRunner';
import { AGENT_REQUEST_FEEDBACK, REQUEST_FEEDBACK_PARAM_NAME } from '#agent/autonomous/functions/agentFeedback';
import { AGENT_COMPLETED_NAME } from '#agent/autonomous/functions/agentFunctions';
import { XML_AGENT_SPAN } from '#agent/autonomous/xml/xmlAutonomousAgent';
Expand All @@ -21,6 +14,7 @@ import { lastText } from '#shared/llm/llm.model';
import type { User } from '#shared/user/user.model';
import { sleep } from '#utils/async-utils';
import { agentContextStorage } from '../../agentContextLocalStorage';
import { type RunAgentConfig } from '../runAgentTypes';

const REQUEST_FEEDBACK_VALUE = 'question is...';
const REQUEST_FEEDBACK_FUNCTION_CALL = `<plan>Requesting feedback</plan>\n<function_calls><function_call><function_name>${AGENT_REQUEST_FEEDBACK}</function_name><parameters><${REQUEST_FEEDBACK_PARAM_NAME}>${REQUEST_FEEDBACK_VALUE}</${REQUEST_FEEDBACK_PARAM_NAME}></parameters></function_call></function_calls>`;
Expand Down
3 changes: 2 additions & 1 deletion src/agent/workflow/workflowAgentRunner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Span } from '@opentelemetry/api';
import { agentContext, agentContextStorage, createContext } from '#agent/agentContextLocalStorage';
import { type AgentExecution, type RunWorkflowConfig, agentExecutions } from '#agent/autonomous/autonomousAgentRunner';
import { type AgentExecution, agentExecutions } from '#agent/autonomous/autonomousAgentRunner';
import { type RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { appContext } from '#app/applicationContext';
import { defaultLLMs } from '#llm/services/defaultLlms';
import { logger } from '#o11y/logger';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/code.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '#fastify/trace-init/trace-init'; // leave an empty line next so this doesn't get sorted from the first line

import type { RunAgentConfig, RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { initApplicationContext } from '#app/applicationContext';
import { shutdownTrace } from '#fastify/trace-init/trace-init';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/debate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '#fastify/trace-init/trace-init'; // leave an empty line next so this doe

import { writeFileSync } from 'node:fs';
import { agentContext, llms } from '#agent/agentContextLocalStorage';
import type { RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { appContext, initApplicationContext } from '#app/applicationContext';
import { shutdownTrace } from '#fastify/trace-init/trace-init';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/detect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '#fastify/trace-init/trace-init'; // leave an empty line next so this doesn't get sorted from the first line

import { agentContext } from '#agent/agentContextLocalStorage';
import type { RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { initApplicationContext } from '#app/applicationContext';
import { shutdownTrace } from '#fastify/trace-init/trace-init';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '#fastify/trace-init/trace-init'; // leave an empty line next so this doe

import { writeFileSync } from 'node:fs';
import { agentContext, llms } from '#agent/agentContextLocalStorage';
import type { RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { appContext, initApplicationContext } from '#app/applicationContext';
import { shutdownTrace } from '#fastify/trace-init/trace-init';
Expand Down
3 changes: 2 additions & 1 deletion src/cli/review.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '#fastify/trace-init/trace-init'; // leave an empty line next so this doesn't get sorted from the first line

import type { RunAgentConfig, RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import type { RunAgentConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { initApplicationContext } from '#app/applicationContext';
import { shutdownTrace } from '#fastify/trace-init/trace-init';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/summarize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '#fastify/trace-init/trace-init'; // leave an empty line next so this doesn't get sorted from the first line

import { writeFileSync } from 'node:fs';
import type { RunAgentConfig, RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { initApplicationContext } from '#app/applicationContext';
import { shutdownTrace } from '#fastify/trace-init/trace-init';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/swe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '#fastify/trace-init/trace-init'; // leave an empty line next so this doesn't get sorted from the first line

import type { RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { initApplicationContext } from '#app/applicationContext';
import { FileSystemRead } from '#functions/storage/fileSystemRead';
Expand Down
3 changes: 2 additions & 1 deletion src/routes/webhooks/gitlab/gitlabRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Type } from '@sinclair/typebox';
import type { FastifyReply } from 'fastify';
import { type RunWorkflowConfig, startAgent } from '#agent/autonomous/autonomousAgentRunner';
import { startAgent } from '#agent/autonomous/autonomousAgentRunner';
import { FileSystemTree } from '#agent/autonomous/functions/fileSystemTree';
import { LiveFiles } from '#agent/autonomous/functions/liveFiles';
import { type RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { appContext } from '#app/applicationContext';
import type { AppFastifyInstance } from '#app/applicationTypes';
Expand Down
2 changes: 1 addition & 1 deletion src/routes/workflows/workflow-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'node:path';
import { join } from 'node:path';
import { Type } from '@sinclair/typebox';
import { getFileSystem } from '#agent/agentContextLocalStorage';
import type { RunWorkflowConfig } from '#agent/autonomous/autonomousAgentRunner';
import type { RunWorkflowConfig } from '#agent/autonomous/runAgentTypes';
import { runWorkflowAgent } from '#agent/workflow/workflowAgentRunner';
import { systemDir, typedaiDirName } from '#app/appDirs';
import type { AppFastifyInstance } from '#app/applicationTypes';
Expand Down