(tools, toolChoice, environment, modelKey = null, provider = null, route = null)
| 580 | * retries until the proxy gives up. |
| 581 | */ |
| 582 | export function buildCompactToolPreambleForProto(tools, toolChoice, environment, modelKey = null, provider = null, route = null) { |
| 583 | if (!Array.isArray(tools) || tools.length === 0) return ''; |
| 584 | const { mode, forceName } = resolveToolChoice(toolChoice); |
| 585 | const dialect = pickToolDialect(modelKey, provider, route); |
| 586 | const protocol = protocolHeaderForTools(dialect, mode, forceName, true); |
| 587 | const names = []; |
| 588 | for (const t of tools) { |
| 589 | if (t?.type !== 'function' || !t.function?.name) continue; |
| 590 | names.push(t.function.name); |
| 591 | } |
| 592 | if (!names.length) return ''; |
| 593 | |
| 594 | const lines = []; |
| 595 | if (environment && typeof environment === 'string' && environment.trim()) { |
| 596 | lines.push('## Environment facts'); |
| 597 | lines.push('The facts below are provided by the calling agent and describe the active execution context. Tool calls operate on these paths.'); |
| 598 | lines.push(''); |
| 599 | lines.push(environment.trim()); |
| 600 | lines.push(''); |
| 601 | lines.push(WORKSPACE_STUB_OVERRIDE); |
| 602 | lines.push(''); |
| 603 | } |
| 604 | lines.push(WORKSPACE_PATH_HINT); |
| 605 | lines.push(''); |
| 606 | lines.push(protocol); |
| 607 | const specificRules = toolSpecificRules(tools); |
| 608 | if (specificRules.length) { |
| 609 | lines.push(''); |
| 610 | lines.push('Tool argument fidelity rules:'); |
| 611 | lines.push(...specificRules); |
| 612 | } |
| 613 | lines.push(''); |
| 614 | lines.push(`Available functions: ${names.join(', ')}.`); |
| 615 | lines.push('Parameter schemas are omitted in this preamble due to total tool-list size. Match each <tool_call> to the function name; the calling agent will validate argument shapes when it executes the call.'); |
| 616 | return lines.join('\n'); |
| 617 | } |
| 618 | |
| 619 | function safeParseJson(s) { |
| 620 | if (typeof s !== 'string') return null; |
no test coverage detected