Skip to content

Commit

Permalink
feat: use framework's tool validation and remove caption (#54)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
  • Loading branch information
Tomas2D authored Nov 7, 2024
1 parent 6663804 commit 77af525
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REDIS_CA_CERT= # optional
REDIS_CACHE_URL=redis://127.0.0.1:6379/1
REDIS_CACHE_CA_CERT= # optional

# Object Storage used for files and their text extractions
# Object Storage used for files and their text extractions
S3_ENDPOINT=
S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@zilliz/milvus2-sdk-node": "^2.4.4",
"ajv": "^8.17.1",
"axios": "^1.7.7",
"bee-agent-framework": "0.0.36",
"bee-agent-framework": "0.0.37",
"bee-observe-connector": "0.0.5",
"bullmq": "5.8.1",
"cache-manager": "^5.7.6",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/runs/execution/event-handlers/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function createStreamingHandler(ctx: AgentContext) {
details: new RunStepToolCalls({
toolCalls: [ctx.toolCall]
}),
metadata: data.iteration.tool_caption ? { caption: data.iteration.tool_caption } : {},
metadata: {},
event: createEventFromMeta(meta)
});
await ORM.em.persistAndFlush(ctx.runStep);
Expand Down
14 changes: 7 additions & 7 deletions src/runs/execution/tools/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,36 +315,36 @@ export async function createToolCall(
) {
if (tool instanceof FileSearchTool) {
return new FileSearchCall({
input: tool.inputSchema().parse(input).query
input: await tool.parse(input).then((result) => result.query)
});
} else if (tool instanceof WikipediaSimilaritySearchTool) {
return new SystemCall({
toolId: SystemTools.WIKIPEDIA,
input: tool.inputSchema().parse(input)
input: await tool.parse(input)
});
} else if (tool instanceof GoogleSearchTool || tool instanceof DuckDuckGoSearchTool) {
return new SystemCall({
toolId: SystemTools.WEB_SEARCH,
input: tool.inputSchema().parse(input)
input: await tool.parse(input)
});
} else if (tool instanceof OpenMeteoTool) {
return new SystemCall({
toolId: SystemTools.WEATHER,
input: tool.inputSchema().parse(input)
input: await tool.parse(input)
});
} else if (tool instanceof ArXivTool) {
return new SystemCall({
toolId: SystemTools.ARXIV,
input: tool.inputSchema().parse(input)
input: await tool.parse(input)
});
} else if (tool instanceof PythonTool) {
return new CodeInterpreterCall({
input: (await tool.inputSchema()).parse(input).code
input: await tool.parse(input).then((result) => result.code)
});
} else if (tool instanceof ReadFileTool) {
return new SystemCall({
toolId: SystemTools.READ_FILE,
input: tool.inputSchema().parse(input)
input: await tool.parse(input)
});
} else if (tool instanceof FunctionTool) {
return new FunctionCall({ name: tool.name, arguments: JSON.stringify(input) });
Expand Down
22 changes: 9 additions & 13 deletions src/runs/execution/tools/read-file-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
Tool,
ToolError
} from 'bee-agent-framework/tools/base';
import { ZodLiteral, z } from 'zod';
import { z } from 'zod';
import { hasAtLeast } from 'remeda';

import { getExtractedFileObject } from '@/files/files.service.js';
import { File } from '@/files/entities/file.entity.js';
Expand All @@ -35,19 +36,14 @@ export class ReadFileTool extends Tool<StringToolOutput, ReadFileToolOptions> {
name = `ReadFile`;
description = 'Retrieve file content.';
inputSchema() {
const fileNames = this.options.files.map((file) => z.literal(file.filename));

return z.object({
filename:
this.options.files.length === 1
? z.literal(this.options.files[0].filename).describe(`Name of the file to read`)
: z
.union(
this.options.files.map((file) => z.literal(file.filename)) as [
ZodLiteral<string>,
ZodLiteral<string>,
...ZodLiteral<string>[]
]
)
.describe('Name of the file to read.')
filename: hasAtLeast(fileNames, 2)
? z.union(fileNames).describe('Name of the file to read.')
: hasAtLeast(fileNames, 1)
? fileNames[0].describe(`Name of the file to read`)
: z.literal('non_existing_file').describe('No files available.')
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/runs/execution/tools/search-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export function createSearchTool(options?: SearchToolOptions, backend = SEARCH_T
return new GoogleSearchTool({
apiKey: BEE_GOOGLE_SEARCH_API_KEY,
cseId: BEE_GOOGLE_SEARCH_CSE_ID,
maxResultsPerPage: 10,
maxResults: 10,
...options
});
case SearchToolBackend.DUCK_DUCK_GO:
return new DuckDuckGoSearchTool({ maxResultsPerPage: 10, ...options });
return new DuckDuckGoSearchTool({ maxResults: 10, ...options });
}
}
14 changes: 7 additions & 7 deletions src/tools/tools.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ function getSystemTools() {
id: SystemTools.WEB_SEARCH,
createdAt: new Date('2024-07-24'),
...searchTool,
inputSchema: searchTool.inputSchema,
inputSchema: searchTool.inputSchema.bind(searchTool),
isExternal: true,
metadata: {
$ui_description_short: 'Retrieve real-time search results from across the internet'
Expand All @@ -483,7 +483,7 @@ function getSystemTools() {
id: SystemTools.WIKIPEDIA,
createdAt: new Date('2024-07-24'),
...wikipediaTool,
inputSchema: wikipediaTool.inputSchema,
inputSchema: wikipediaTool.inputSchema.bind(wikipediaTool),
isExternal: true,
metadata: {
$ui_description_short:
Expand All @@ -497,7 +497,7 @@ function getSystemTools() {
id: SystemTools.WEATHER,
createdAt: new Date('2024-07-25'),
...weatherTool,
inputSchema: weatherTool.inputSchema,
inputSchema: weatherTool.inputSchema.bind(weatherTool),
isExternal: true,
metadata: {
$ui_description_short:
Expand All @@ -511,7 +511,7 @@ function getSystemTools() {
id: SystemTools.ARXIV,
createdAt: new Date('2024-07-25'),
...arXivTool,
inputSchema: arXivTool.inputSchema,
inputSchema: arXivTool.inputSchema.bind(arXivTool),
isExternal: true,
metadata: {
$ui_description_short:
Expand All @@ -525,7 +525,7 @@ function getSystemTools() {
id: 'read_file',
createdAt: new Date('2024-10-02'),
...readFile,
inputSchema: readFile.inputSchema,
inputSchema: readFile.inputSchema.bind(readFile),
isExternal: false,
metadata: {
$ui_description_short: 'Read and interpret basic files'
Expand All @@ -547,7 +547,7 @@ function getSystemTools() {
id: 'file_search',
createdAt: new Date('2024-07-31'),
...fileSearch,
inputSchema: fileSearch.inputSchema,
inputSchema: fileSearch.inputSchema.bind(fileSearch),
isExternal: false,
metadata: {
$ui_description_short: 'Access and interpret file content by using advanced search techniques'
Expand All @@ -560,7 +560,7 @@ function getSystemTools() {
id: 'code_interpreter',
createdAt: new Date('2024-07-01'),
...pythonTool,
inputSchema: pythonTool.inputSchema,
inputSchema: pythonTool.inputSchema.bind(pythonTool),
isExternal: true,
metadata: {
$ui_description_short:
Expand Down

0 comments on commit 77af525

Please sign in to comment.