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
2 changes: 2 additions & 0 deletions multimodal/omni-tars/core/src/AgentComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export class AgentComposer {
*/
async initialize(): Promise<void> {
for (const plugin of this.plugins) {
const start = Date.now();
await plugin.initialize?.();
this.logger.info(`initialize agent plugin ${plugin.name} cost: `, Date.now() - start);
}
}

Expand Down
3 changes: 2 additions & 1 deletion multimodal/omni-tars/mcp-agent/src/McpAgentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class McpAgentPlugin extends AgentPlugin {
}

async initialize(): Promise<void> {
await this.mcpManager.init();
//FIXME:Temporarily remove await to speed up the agent initialization process; the logic of mcpManager.getClient() needs to be added later
this.mcpManager.init();

// Initialize tools
this.tools = [
Expand Down
2 changes: 1 addition & 1 deletion multimodal/omni-tars/omni-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { ComposableAgent } from '@omni-tars/core';
import { AgentWebUIImplementation } from '@tarko/interface';
import { AgentWebUIImplementation } from '@tarko/interface';
import { getComposableOption, OmniTarsOption } from './options';

const sandboxBaseUrl = process.env.AIO_SANDBOX_URL ?? '.';
Expand Down
113 changes: 67 additions & 46 deletions multimodal/omni-tars/omni-agent/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,87 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { CodeAgentExtraOption, codePluginBuilder, CodeToolCallEngineProvider } from "@omni-tars/code-agent";
import { AgentMode, ComposableAgentOptions, createComposableToolCallEngineFactory } from "@omni-tars/core";
import { GuiAgentPlugin, GuiToolCallEngineProvider, OperatorManager } from "@omni-tars/gui-agent";
import { mcpPluginBuilder, MCPTarsExtraOption, McpToolCallEngineProvider } from "@omni-tars/mcp-agent";
import { AgentAppConfig } from "@tarko/interface";

import {
CodeAgentExtraOption,
codePluginBuilder,
CodeToolCallEngineProvider,
} from '@omni-tars/code-agent';
import {
AgentMode,
ComposableAgentOptions,
createComposableToolCallEngineFactory,
} from '@omni-tars/core';
import { GuiAgentPlugin, GuiToolCallEngineProvider, OperatorManager } from '@omni-tars/gui-agent';
import {
mcpPluginBuilder,
MCPTarsExtraOption,
McpToolCallEngineProvider,
} from '@omni-tars/mcp-agent';
import { AgentAppConfig } from '@tarko/interface';

const mcpToolCallEngine = new McpToolCallEngineProvider();

const omniToolCallEngine = createComposableToolCallEngineFactory({
engines: [new GuiToolCallEngineProvider('omni'), mcpToolCallEngine, new CodeToolCallEngineProvider()],
engines: [
new GuiToolCallEngineProvider('omni'),
mcpToolCallEngine,
new CodeToolCallEngineProvider(),
],
defaultEngine: mcpToolCallEngine,
});

const guiToolCallEngine = createComposableToolCallEngineFactory({ engines: [new GuiToolCallEngineProvider('gui')] });
const guiToolCallEngine = createComposableToolCallEngineFactory({
engines: [new GuiToolCallEngineProvider('gui')],
});

export type OmniTarsOption = AgentAppConfig &
MCPTarsExtraOption &
CodeAgentExtraOption & {
agentMode: AgentMode;
browserMode: 'dom' | 'visual-grounding' | 'hybrid';
};

export function getComposableOption(options: OmniTarsOption) {
const {
tavilyApiKey,
googleApiKey,
googleMcpUrl,
sandboxUrl,
ignoreSandboxCheck,
linkReaderAK,
linkReaderMcpUrl,
agentMode = 'omni',
browserMode = 'hybrid',
...restOptions
} = options;

export type OmniTarsOption = AgentAppConfig & MCPTarsExtraOption & CodeAgentExtraOption & {
agentMode: AgentMode
};
const baseOptions: Partial<ComposableAgentOptions> = {
...restOptions,
maxTokens: 32768,
enableStreamingToolCallEvents: true,
};

const guiPlugin = new GuiAgentPlugin({
operatorManager: OperatorManager.createHybird(options.sandboxUrl),
});

export function getComposableOption(options: OmniTarsOption) {
const {
if (agentMode === 'gui') {
baseOptions.toolCallEngine = guiToolCallEngine;
baseOptions.plugins = [guiPlugin];
} else if (agentMode === 'omni') {
baseOptions.toolCallEngine = omniToolCallEngine;
baseOptions.plugins = [
mcpPluginBuilder({
tavilyApiKey,
googleApiKey,
googleMcpUrl,
sandboxUrl,
ignoreSandboxCheck,
linkReaderAK,
linkReaderMcpUrl,
agentMode = 'omni',
...restOptions
} = options;

const baseOptions: Partial<ComposableAgentOptions> = {
...restOptions,
maxTokens: 32768,
enableStreamingToolCallEvents: true,
};
}),
codePluginBuilder({ sandboxUrl, ignoreSandboxCheck }),
guiPlugin,
];
}

if(agentMode === 'gui') {
baseOptions.toolCallEngine = guiToolCallEngine;
baseOptions.plugins = [
new GuiAgentPlugin({ operatorManager: OperatorManager.createHybird(options.sandboxUrl) }),
];
} else if(agentMode === 'omni') {
baseOptions.toolCallEngine = omniToolCallEngine;
baseOptions.plugins = [
mcpPluginBuilder({
tavilyApiKey,
googleApiKey,
googleMcpUrl,
linkReaderAK,
linkReaderMcpUrl,
}),
codePluginBuilder({ sandboxUrl, ignoreSandboxCheck }),
new GuiAgentPlugin({ operatorManager: OperatorManager.createHybird(options.sandboxUrl) }),
];
}

return baseOptions as ComposableAgentOptions;
}
return baseOptions as ComposableAgentOptions;
}
37 changes: 26 additions & 11 deletions multimodal/tarko/agent-server-next/examples/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { getContext } from 'hono/context-storage';
import { AuthHook, CorsHook, AgentServer, ContextStorageHook } from '../src/index';
import { AuthHook, CorsHook, AgentServer, ContextStorageHook } from '../src/index';
import { resolve } from 'path';
import { ContextVariables } from '../src/types';

Expand Down Expand Up @@ -42,7 +42,22 @@ const server = new AgentServer({
type: 'string',
title: 'Agent Mode',
enum: ['omni', 'gui'],
enumLabels: ['Omni', 'GUI'],
default: 'omni',
placement: 'chat-bottom',
},

browserMode: {
type: 'string',
title: 'Browser Control',
enum: ['hybrid'],
enumLabels: ['混合模式'],
default: 'hybrid',
placement: 'chat-bottom',
visible: {
dependsOn: 'agentMode',
when: 'gui',
},
},
},
},
Expand All @@ -60,16 +75,16 @@ const server = new AgentServer({
},
models: [
{
id: "ep-20250909173748-wcfb2",
provider: "volcengine",
displayName: "T6-SFT",
id: 'ep-20250909173748-wcfb2',
provider: 'volcengine',
displayName: 'T6-SFT',
baseURL: process.env.OMNI_TARS_BASE_URL,
apiKey: process.env.OMNI_TARS_API_KEY,
},
{
id: "ep-20250905175225-hlrvd",
provider: "volcengine",
displayName: "T5-RL",
id: 'ep-20250905175225-hlrvd',
provider: 'volcengine',
displayName: 'T5-RL',
baseURL: process.env.OMNI_TARS_BASE_URL,
apiKey: process.env.OMNI_TARS_API_KEY,
},
Expand Down Expand Up @@ -101,15 +116,15 @@ const logger = {
name: 'custom',
info: (...splat) => {
const requestId = getContext<{ Variables: ContextVariables }>().var.requestId;
console.log(`[CUSTOM LOGGER] ${requestId}`, ...splat)
console.log(`[CUSTOM LOGGER] ${requestId}`, ...splat);
},
warn: console.warn,
error: console.error,
debug: console.debug,
setLevel: () => { }
}
setLevel: () => {},
};

server.setLogger(logger)
server.setLogger(logger);
server.registerHook(AuthHook);
server.registerHook(CorsHook);
server.registerHook(ContextStorageHook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function sessionRestoreMiddleware(

// If not exist, restored the AgentSession instance based on the database data.
if (!session) {
logger.info('session instance not exist, prepare to restore')
logger.info('session instance not exist, prepare to restore');

const start = Date.now();

Expand All @@ -47,6 +47,8 @@ export async function sessionRestoreMiddleware(
restored.storageUnsubscribe &&
(server.storageUnsubscribes[sessionId] = restored.storageUnsubscribe);
}
} else {
logger.info('get session from sessionPool, sessionId:', session.id);
}

if (!session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class AgentSession {
throw new Error('Cannot found available resolved agent');
}

// Get stored events for this session before creating the agent
// Get stored events for this session before creating the agent
const storedEvents = this.server.daoFactory
? await this.server.daoFactory.getSessionEvents(this.id)
: [];
Expand Down Expand Up @@ -187,15 +187,26 @@ export class AgentSession {
// Log AGIO initialization
console.debug('AGIO collector initialized', { provider: agentOptions.agio.provider });
}

this.logger.info('create new agent with config: ', JSON.stringify({
agent: agentOptions.agent,
share: agentOptions.share,
workspace: agentOptions.workspace,
thinking: agentOptions.thinking,
name: agentOptions.name,
runtimeSettings: transformedOptions
}, null, 2));

this.logger.info(
'create new agent with config: ',
JSON.stringify(
{
agent: agentOptions.agent,
share: agentOptions.share,
workspace: agentOptions.workspace,
thinking: agentOptions.thinking,
name: agentOptions.name,
model: {
id: agentOptions.model?.id,
provider: agentOptions.model?.provider,
},
runtimeSettings: transformedOptions,
},
null,
2,
),
);

return wrappedAgent;
}
Expand Down Expand Up @@ -552,6 +563,4 @@ export class AgentSession {
}
}



export default AgentSession;