Skip to content

Commit 9e5db17

Browse files
committed
docs
1 parent 7507e09 commit 9e5db17

7 files changed

Lines changed: 104 additions & 48 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agent-swarm-kit",
3-
"version": "1.1.126",
3+
"version": "1.1.128",
44
"description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
55
"author": {
66
"name": "Petr Tripolsky",

src/helpers/toJsonSchema.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { IOutlineObjectFormat, IOutlineSchemaFormat } from "../interfaces/Outline.interface";
2+
3+
/**
4+
* Converts a given schema object into a JSON schema format object.
5+
*
6+
* @param {string} name - The name of the schema.
7+
* @param {IOutlineObjectFormat} schema - The schema definition object.
8+
* @returns {IOutlineSchemaFormat}
9+
* An object containing the JSON schema representation.
10+
*/
11+
export const toJsonSchema = (name: string, schema: IOutlineObjectFormat): IOutlineSchemaFormat => ({
12+
type: "json_schema",
13+
json_schema: {
14+
name,
15+
strict: true,
16+
schema,
17+
},
18+
});
19+
20+
export default toJsonSchema;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,5 @@ export const Utils = {
283283
PersistPolicyUtils,
284284
PersistEmbeddingUtils,
285285
};
286+
287+
export { toJsonSchema } from "./helpers/toJsonSchema";

src/interfaces/Outline.interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export interface IOutlineSchemaFormat {
4848
export interface IOutlineObjectFormat {
4949
/**
5050
* The root type of the outline format (e.g., "object").
51-
* Should be "json_object" for partial JSON schemas or "json_schema" for full matching schemas.
51+
* If openai used Should be "json_object" for partial JSON schemas or "json_schema" for full matching schemas.
52+
* If ollama or `toJsonSchema` function used should just pass "object"
5253
*/
5354
type: string;
5455

src/lib/services/base/DocService.ts

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import ComputeSchemaService from "../schema/ComputeSchemaService";
2727
import OutlineValidationService from "../validation/OutlineValidationService";
2828
import OutlineSchemaService from "../schema/OutlineSchemaService";
2929
import {
30+
IOutlineObjectFormat,
3031
IOutlineSchema,
32+
IOutlineSchemaFormat,
3133
} from "../../../interfaces/Outline.interface";
3234

3335
/**
@@ -485,56 +487,74 @@ export class DocService {
485487
}
486488
}
487489

488-
if ("properties" in outlineSchema.format) {
489-
result.push("");
490-
result.push("## Output format");
491-
result.push("");
492-
result.push("*Partial template match*");
493-
result.push("");
494-
const entries = Object.entries(outlineSchema.format.properties);
495-
entries.forEach(([key, { type, description, enum: e }], idx) => {
490+
const writeObjectFormat = (object: IOutlineObjectFormat, strict: boolean) => {
491+
if ("properties" in object) {
496492
result.push("");
497-
result.push(`> **${idx + 1}. ${sanitizeMarkdown(key)}**`);
498-
{
499-
result.push("");
500-
result.push(`*Type:* \`${sanitizeMarkdown(type)}\``);
501-
}
502-
{
503-
result.push("");
504-
result.push(`*Description:* \`${sanitizeMarkdown(description)}\``);
505-
}
506-
if (e) {
493+
result.push("## Output format");
494+
result.push("");
495+
result.push(strict ? "*Strict template match*" : "*Partial template match*");
496+
const entries = Object.entries(object.properties);
497+
entries.forEach(([key, { type, description, enum: e }], idx) => {
507498
result.push("");
508-
result.push(`*Enum:* \`${e.map(sanitizeMarkdown).join(", ")}\``);
509-
}
510-
if ("required" in outlineSchema.format) {
499+
result.push(`> **${idx + 1}. ${sanitizeMarkdown(key)}**`);
500+
{
501+
result.push("");
502+
result.push(`*Type:* \`${sanitizeMarkdown(type)}\``);
503+
}
504+
{
505+
result.push("");
506+
result.push(
507+
`*Description:* \`${sanitizeMarkdown(description)}\``
508+
);
509+
}
510+
if (e) {
511+
result.push("");
512+
result.push(`*Enum:* \`${e.map(sanitizeMarkdown).join(", ")}\``);
513+
}
514+
if ("required" in object) {
515+
result.push("");
516+
result.push(
517+
`*Required:* [${object.required.includes(key) ? "x" : " "}]`
518+
);
519+
}
520+
});
521+
if (!entries.length) {
511522
result.push("");
512-
result.push(
513-
`*Required:* [${
514-
outlineSchema.format.required.includes(key) ? "x" : " "
515-
}]`
516-
);
523+
result.push(`*Empty parameters*`);
517524
}
518-
});
519-
if (!entries.length) {
520525
result.push("");
521-
result.push(`*Empty parameters*`);
522526
}
523-
result.push("");
524-
}
527+
};
525528

526-
if (outlineSchema.format.type === "json_schema") {
527-
result.push("");
528-
result.push("## Output format");
529-
result.push("");
530-
result.push("*Strict template match*");
531-
result.push("");
532-
result.push("```json");
533-
result.push(JSON.stringify(outlineSchema.format, null, 2));
534-
result.push("```");
535-
result.push("");
529+
const writeStrictFormat = (schema: IOutlineSchemaFormat) => {
530+
if (schema?.type === "json_schema") {
531+
result.push("");
532+
result.push("## Output format");
533+
result.push("");
534+
result.push("*Strict template match*");
535+
result.push("");
536+
result.push("```json");
537+
result.push(JSON.stringify(schema, null, 2));
538+
result.push("```");
539+
result.push("");
540+
}
541+
};
542+
543+
const writeFormat = () => {
544+
let object: any = outlineSchema.format;
545+
if (object?.json_schema?.schema?.type === "object") {
546+
writeObjectFormat(object.json_schema.schema, true);
547+
return;
548+
}
549+
if (object.properties) {
550+
writeObjectFormat(object, false);
551+
return;
552+
}
553+
writeStrictFormat(object);
536554
}
537555

556+
writeFormat();
557+
538558
const getValidations = () => {
539559
if (outlineSchema.validations) {
540560
return outlineSchema.validations
@@ -553,7 +573,9 @@ export class DocService {
553573
if (!validations[i].docDescription) {
554574
continue;
555575
}
556-
result.push(`${i + 1}. \`${sanitizeMarkdown(validations[i].docDescription)}\``);
576+
result.push(
577+
`${i + 1}. \`${sanitizeMarkdown(validations[i].docDescription)}\``
578+
);
557579
result.push("");
558580
}
559581
}

types.d.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,8 @@ interface IOutlineSchemaFormat {
30693069
interface IOutlineObjectFormat {
30703070
/**
30713071
* The root type of the outline format (e.g., "object").
3072-
* Should be "json_object" for partial JSON schemas or "json_schema" for full matching schemas.
3072+
* If openai used Should be "json_object" for partial JSON schemas or "json_schema" for full matching schemas.
3073+
* If ollama or `toJsonSchema` function used should just pass "object"
30733074
*/
30743075
type: string;
30753076
/**
@@ -15731,6 +15732,16 @@ declare const Adapter: AdapterUtils;
1573115732
*/
1573215733
declare const beginContext: <T extends (...args: any[]) => any>(run: T) => ((...args: Parameters<T>) => ReturnType<T>);
1573315734

15735+
/**
15736+
* Converts a given schema object into a JSON schema format object.
15737+
*
15738+
* @param {string} name - The name of the schema.
15739+
* @param {IOutlineObjectFormat} schema - The schema definition object.
15740+
* @returns {IOutlineSchemaFormat}
15741+
* An object containing the JSON schema representation.
15742+
*/
15743+
declare const toJsonSchema: (name: string, schema: IOutlineObjectFormat) => IOutlineSchemaFormat;
15744+
1573415745
declare const Utils: {
1573515746
PersistStateUtils: typeof PersistStateUtils;
1573615747
PersistSwarmUtils: typeof PersistSwarmUtils;
@@ -15741,4 +15752,4 @@ declare const Utils: {
1574115752
PersistEmbeddingUtils: typeof PersistEmbeddingUtils;
1574215753
};
1574315754

15744-
export { Adapter, Chat, ChatInstance, Compute, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchemaInternal, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type IChatArgs, type IChatInstance, type IChatInstanceCallbacks, type ICompletionArgs, type ICompletionSchema, type IComputeSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMCPSchema, type IMCPTool, type IMCPToolCallDto, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type INavigateToAgentParams, type INavigateToTriageParams, type IOutgoingMessage, type IOutlineFormat, type IOutlineHistory, type IOutlineMessage, type IOutlineObjectFormat, type IOutlineResult, type IOutlineSchema, type IOutlineSchemaFormat, type IOutlineValidationFn, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPipelineSchema, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, type IWikiSchema, Logger, LoggerInstance, MCP, type MCPToolProperties, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, SchemaContextService, type SendMessageFn, SharedCompute, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TOperatorInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, Utils, addAgent, addAgentNavigation, addCompletion, addCompute, addEmbedding, addMCP, addOutline, addPipeline, addPolicy, addState, addStorage, addSwarm, addTool, addTriageNavigation, addWiki, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitToolRequest, commitToolRequestForce, commitUserMessage, commitUserMessageForce, complete, createNavigateToAgent, createNavigateToTriageAgent, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, fork, getAgent, getAgentHistory, getAgentName, getAssistantHistory, getCheckBusy, getCompletion, getCompute, getEmbeding, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getMCP, getNavigationRoute, getPayload, getPipeline, getPolicy, getRawHistory, getSessionContext, getSessionMode, getState, getStorage, getSwarm, getTool, getToolNameForModel, getUserHistory, getWiki, hasNavigation, hasSession, json, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, notify, notifyForce, overrideAgent, overrideCompletion, overrideCompute, overrideEmbeding, overrideMCP, overrideOutline, overridePipeline, overridePolicy, overrideState, overrideStorage, overrideSwarm, overrideTool, overrideWiki, question, questionForce, runStateless, runStatelessForce, scope, session, setConfig, startPipeline, swarm };
15755+
export { Adapter, Chat, ChatInstance, Compute, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAgentSchemaInternal, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type IChatArgs, type IChatInstance, type IChatInstanceCallbacks, type ICompletionArgs, type ICompletionSchema, type IComputeSchema, type ICustomEvent, type IEmbeddingSchema, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMCPSchema, type IMCPTool, type IMCPToolCallDto, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type INavigateToAgentParams, type INavigateToTriageParams, type IOutgoingMessage, type IOutlineFormat, type IOutlineHistory, type IOutlineMessage, type IOutlineObjectFormat, type IOutlineResult, type IOutlineSchema, type IOutlineSchemaFormat, type IOutlineValidationFn, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPipelineSchema, type IPolicySchema, type ISessionConfig, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, type IWikiSchema, Logger, LoggerInstance, MCP, type MCPToolProperties, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, SchemaContextService, type SendMessageFn, SharedCompute, SharedState, SharedStorage, State, Storage, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TOperatorInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, Utils, addAgent, addAgentNavigation, addCompletion, addCompute, addEmbedding, addMCP, addOutline, addPipeline, addPolicy, addState, addStorage, addSwarm, addTool, addTriageNavigation, addWiki, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitToolRequest, commitToolRequestForce, commitUserMessage, commitUserMessageForce, complete, createNavigateToAgent, createNavigateToTriageAgent, disposeConnection, dumpAgent, dumpClientPerformance, dumpDocs, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, fork, getAgent, getAgentHistory, getAgentName, getAssistantHistory, getCheckBusy, getCompletion, getCompute, getEmbeding, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getMCP, getNavigationRoute, getPayload, getPipeline, getPolicy, getRawHistory, getSessionContext, getSessionMode, getState, getStorage, getSwarm, getTool, getToolNameForModel, getUserHistory, getWiki, hasNavigation, hasSession, json, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, notify, notifyForce, overrideAgent, overrideCompletion, overrideCompute, overrideEmbeding, overrideMCP, overrideOutline, overridePipeline, overridePolicy, overrideState, overrideStorage, overrideSwarm, overrideTool, overrideWiki, question, questionForce, runStateless, runStatelessForce, scope, session, setConfig, startPipeline, swarm, toJsonSchema };

0 commit comments

Comments
 (0)