Skip to content

Commit 23b5335

Browse files
Copilothotlong
andauthored
fix: address code review feedback — fix maxIterations logic, remove any types, enhance JSDoc
Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/10c08b4e-c31c-42cd-a9d4-27917289db5b Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f4e8229 commit 23b5335

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

packages/services/service-ai/src/agent-runtime.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@ export class AgentRuntime {
7575
/**
7676
* Derive {@link AIRequestOptions} from an agent definition.
7777
*
78-
* Tool references declared in `agent.tools` are resolved against
79-
* `availableTools` (i.e. the full ToolRegistry definitions).
80-
* Any unresolved references are silently ignored.
78+
* Tool references declared in `agent.tools` are resolved by name against
79+
* `availableTools` (i.e. the full set of ToolRegistry definitions).
80+
* Any unresolved references (tools the agent declares but that are not
81+
* registered) are silently skipped — this is intentional so that agents
82+
* can be defined before all tools are available.
83+
*
84+
* @param agent - The agent definition to derive options from
85+
* @param availableTools - All tool definitions currently registered in the ToolRegistry
86+
* @returns Request options with model config and resolved tool definitions
8187
*/
8288
buildRequestOptions(
8389
agent: Agent,

packages/services/service-ai/src/routes/agent-routes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ export function buildAgentRoutes(
9797
// Use chatWithTools for automatic tool resolution
9898
const result = await aiService.chatWithTools(fullMessages, {
9999
...mergedOptions,
100-
maxIterations: agent.guardrails?.maxTokensPerInvocation
101-
? undefined // let default apply
102-
: undefined,
100+
maxIterations: agent.planning?.maxIterations,
103101
});
104102

105103
return { status: 200, body: result };

packages/services/service-ai/src/tools/data-tools.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ import type { AIToolDefinition, IDataEngine, IMetadataService } from '@objectsta
44
import type { ToolHandler } from './tool-registry.js';
55
import type { ToolRegistry } from './tool-registry.js';
66

7+
// ---------------------------------------------------------------------------
8+
// Internal type aliases for metadata payloads (returned as `unknown` from
9+
// IMetadataService — we cast to these lightweight shapes for field access).
10+
// ---------------------------------------------------------------------------
11+
12+
/** Minimal shape of an object definition as returned by IMetadataService. */
13+
interface ObjectDef {
14+
name: string;
15+
label?: string;
16+
fields?: Record<string, FieldDef>;
17+
}
18+
19+
/** Minimal shape of a field definition inside an object. */
20+
interface FieldDef {
21+
type?: string;
22+
label?: string;
23+
required?: boolean;
24+
reference?: string;
25+
options?: unknown;
26+
}
27+
728
// ---------------------------------------------------------------------------
829
// Data context — injected once at registration time
930
// ---------------------------------------------------------------------------
@@ -198,7 +219,7 @@ export const DATA_TOOL_DEFINITIONS: AIToolDefinition[] = [
198219
function createListObjectsHandler(ctx: DataToolContext): ToolHandler {
199220
return async () => {
200221
const objects = await ctx.metadataService.listObjects();
201-
const summary = objects.map((o: any) => ({
222+
const summary = (objects as ObjectDef[]).map(o => ({
202223
name: o.name,
203224
label: o.label ?? o.name,
204225
}));
@@ -214,11 +235,10 @@ function createDescribeObjectHandler(ctx: DataToolContext): ToolHandler {
214235
return JSON.stringify({ error: `Object "${objectName}" not found` });
215236
}
216237

217-
const def = objectDef as any;
238+
const def = objectDef as ObjectDef;
218239
const fields = def.fields ?? {};
219-
const fieldSummary: Record<string, any> = {};
220-
for (const [key, fd] of Object.entries(fields)) {
221-
const f = fd as any;
240+
const fieldSummary: Record<string, Record<string, unknown>> = {};
241+
for (const [key, f] of Object.entries(fields)) {
222242
fieldSummary[key] = {
223243
type: f.type,
224244
label: f.label ?? key,
@@ -289,6 +309,9 @@ function createGetRecordHandler(ctx: DataToolContext): ToolHandler {
289309
};
290310
}
291311

312+
/** Aggregation function names supported by the data engine. */
313+
type AggFn = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct';
314+
292315
function createAggregateDataHandler(ctx: DataToolContext): ToolHandler {
293316
return async (args) => {
294317
const { objectName, aggregations, groupBy, where } = args as {
@@ -302,7 +325,7 @@ function createAggregateDataHandler(ctx: DataToolContext): ToolHandler {
302325
where,
303326
groupBy,
304327
aggregations: aggregations.map(a => ({
305-
function: a.function as any,
328+
function: a.function as AggFn,
306329
field: a.field,
307330
alias: a.alias,
308331
})),

0 commit comments

Comments
 (0)