Skip to content

Commit 2b820ac

Browse files
committed
Merge branch 'dev'
2 parents a16d622 + 675ad98 commit 2b820ac

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ UTCP offers a unified framework for integrating disparate tools and services, ma
1515
* **Scalability**: Designed to handle a large number of tools and providers without compromising performance.
1616
* **Extensibility**: A pluggable architecture allows developers to easily add new communication protocols, tool storage mechanisms, and search strategies without modifying the core library.
1717
* **Interoperability**: With a growing ecosystem of protocol plugins—including HTTP, MCP, Text, File, and CLI—UTCP can integrate with almost any existing service or infrastructure.
18+
* **Code Execution Mode**: Execute TypeScript code with hierarchical access to tools, complete console output capture, and runtime interface introspection for powerful AI agent workflows.
1819
* **Type Safety**: Built on well-defined TypeScript interfaces and runtime validation powered by Zod, making it robust and developer-friendly.
1920
* **Secure Variable Management**: Namespace-isolated variables prevent leakage between manuals, with support for environment variables and .env files.
2021

@@ -28,13 +29,13 @@ Install UTCP packages from npm:
2829

2930
```bash
3031
# Install core SDK and desired protocol plugins
31-
npm install @utcp/sdk @utcp/http @utcp/mcp @utcp/text @utcp/file
32+
npm install @utcp/sdk @utcp/http @utcp/mcp @utcp/text @utcp/file @utcp/code-mode
3233

3334
# Optional: Add dotenv variable loader for Node.js
3435
npm install @utcp/dotenv-loader
3536

3637
# Or using bun
37-
bun add @utcp/sdk @utcp/http @utcp/mcp @utcp/text @utcp/file
38+
bun add @utcp/sdk @utcp/http @utcp/mcp @utcp/text @utcp/file @utcp/code-mode
3839
```
3940

4041
### For Development
@@ -439,6 +440,81 @@ const cliTemplate = serializer.validateDict({
439440
});
440441
```
441442

443+
## Code Execution Mode
444+
445+
The `@utcp/code-mode` package provides a powerful extension that allows executing TypeScript code with direct access to registered tools, perfect for AI agents and complex workflows:
446+
447+
```typescript
448+
import { CodeModeUtcpClient } from '@utcp/code-mode';
449+
450+
async function main() {
451+
const client = await CodeModeUtcpClient.create();
452+
453+
// Register your tools (same as regular UTCP)
454+
await client.registerManual({
455+
name: 'math_tools',
456+
call_template_type: 'text',
457+
content: '...' // Your tool definitions
458+
});
459+
460+
// Execute TypeScript code with hierarchical tool access
461+
const { result, logs } = await client.callToolChain(`
462+
console.log('Starting calculation...');
463+
464+
// Tools are organized by namespace: manual.tool
465+
const sum = await math_tools.add({ a: 10, b: 20 });
466+
console.log('Sum result:', sum.result);
467+
468+
// Access TypeScript interfaces at runtime for introspection
469+
const addInterface = __getToolInterface('math_tools.add');
470+
console.log('Tool interface:', addInterface);
471+
472+
// Chain multiple tool calls
473+
const result = await math_tools.multiply({
474+
a: sum.result,
475+
b: 2
476+
});
477+
478+
return result;
479+
`);
480+
481+
console.log('Execution result:', result);
482+
console.log('Console output:', logs);
483+
// logs: ['Starting calculation...', 'Sum result: 30', 'Tool interface: ...']
484+
485+
await client.close();
486+
}
487+
```
488+
489+
### Code Mode Features
490+
491+
- **Hierarchical Tool Access**: Tools organized by manual namespace (`manual.tool()`) preventing naming conflicts
492+
- **Console Output Capture**: All console output automatically captured and returned
493+
- **Runtime Interface Introspection**: Access TypeScript interface definitions during execution
494+
- **Type Safety**: Generated TypeScript interfaces for all tools with hierarchical namespaces
495+
- **Secure Execution**: VM-based sandboxed execution with timeout protection
496+
- **AI Agent Ready**: Built-in prompt template to guide AI agents on proper usage
497+
498+
### Perfect for AI Agents
499+
500+
The `CodeModeUtcpClient.AGENT_PROMPT_TEMPLATE` provides comprehensive guidance for AI agents:
501+
502+
```typescript
503+
// Add to your AI system prompt
504+
const systemPrompt = `
505+
${CodeModeUtcpClient.AGENT_PROMPT_TEMPLATE}
506+
507+
Your additional instructions...
508+
`;
509+
```
510+
511+
The template includes:
512+
- Tool discovery workflow
513+
- Interface introspection patterns
514+
- Best practices for hierarchical tool access
515+
- Error handling guidelines
516+
- Runtime context documentation
517+
442518
## Monorepo Structure
443519

444520
```
@@ -449,6 +525,7 @@ typescript-utcp/
449525
│ ├── mcp/ # MCP protocol plugin
450526
│ ├── text/ # Text/string content protocol plugin (browser-compatible)
451527
│ ├── file/ # File system protocol plugin (Node.js only)
528+
│ ├── code-mode/ # TypeScript code execution with hierarchical tool access
452529
│ ├── dotenv-loader/ # DotEnv variable loader plugin (Node.js only)
453530
│ ├── direct-call/ # Direct call protocol plugin
454531
│ └── cli/ # CLI protocol plugin
@@ -462,6 +539,7 @@ Each package is independently published to npm:
462539
- `@utcp/mcp` - MCP protocol support
463540
- `@utcp/text` - Direct text/string content (browser-compatible)
464541
- `@utcp/file` - File system operations (Node.js only)
542+
- `@utcp/code-mode` - TypeScript code execution with hierarchical tool access
465543
- `@utcp/dotenv-loader` - DotEnv variable loader (Node.js only)
466544
- `@utcp/direct-call` - Direct function call protocol
467545
- `@utcp/cli` - Command-line tools

0 commit comments

Comments
 (0)