@agentica/core 0.19.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +115 -413
  2. package/lib/MicroAgentica.js +4 -1
  3. package/lib/MicroAgentica.js.map +1 -1
  4. package/lib/context/AgenticaOperation.d.ts +3 -4
  5. package/lib/context/internal/AgenticaOperationComposer.js +1 -1
  6. package/lib/context/internal/AgenticaOperationComposer.js.map +1 -1
  7. package/lib/context/internal/AgenticaOperationComposer.spec.js +39 -10
  8. package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
  9. package/lib/functional/assertHttpLlmApplication.js +168 -168
  10. package/lib/functional/assertMcpController.d.ts +24 -0
  11. package/lib/functional/assertMcpController.js +1699 -0
  12. package/lib/functional/assertMcpController.js.map +1 -0
  13. package/lib/functional/validateHttpLlmApplication.js +148 -148
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.js +1 -1
  16. package/lib/index.js.map +1 -1
  17. package/lib/index.mjs +1999 -406
  18. package/lib/index.mjs.map +1 -1
  19. package/lib/orchestrate/call.js +1 -1
  20. package/lib/orchestrate/call.js.map +1 -1
  21. package/lib/orchestrate/execute.js +13 -7
  22. package/lib/orchestrate/execute.js.map +1 -1
  23. package/lib/orchestrate/initialize.js +60 -60
  24. package/lib/structures/IAgenticaController.d.ts +8 -4
  25. package/lib/structures/IAgenticaExecutor.d.ts +10 -6
  26. package/lib/structures/IMicroAgenticaExecutor.d.ts +4 -1
  27. package/lib/structures/mcp/index.d.ts +0 -2
  28. package/lib/structures/mcp/index.js +0 -2
  29. package/lib/structures/mcp/index.js.map +1 -1
  30. package/package.json +3 -3
  31. package/src/MicroAgentica.ts +3 -1
  32. package/src/context/AgenticaOperation.ts +5 -6
  33. package/src/context/internal/AgenticaOperationComposer.spec.ts +45 -14
  34. package/src/context/internal/AgenticaOperationComposer.ts +9 -2
  35. package/src/functional/assertMcpController.ts +48 -0
  36. package/src/index.ts +1 -1
  37. package/src/orchestrate/call.ts +14 -4
  38. package/src/orchestrate/execute.ts +13 -7
  39. package/src/structures/IAgenticaController.ts +9 -4
  40. package/src/structures/IAgenticaExecutor.ts +16 -8
  41. package/src/structures/IMicroAgenticaExecutor.ts +10 -4
  42. package/src/structures/mcp/index.ts +0 -2
  43. package/lib/functional/assertMcpLlmApplication.d.ts +0 -18
  44. package/lib/functional/assertMcpLlmApplication.js +0 -74
  45. package/lib/functional/assertMcpLlmApplication.js.map +0 -1
  46. package/lib/structures/mcp/IMcpLlmApplication.d.ts +0 -9
  47. package/lib/structures/mcp/IMcpLlmApplication.js +0 -3
  48. package/lib/structures/mcp/IMcpLlmApplication.js.map +0 -1
  49. package/lib/structures/mcp/IMcpLlmFunction.d.ts +0 -17
  50. package/lib/structures/mcp/IMcpLlmFunction.js +0 -3
  51. package/lib/structures/mcp/IMcpLlmFunction.js.map +0 -1
  52. package/src/functional/assertMcpLlmApplication.ts +0 -32
  53. package/src/structures/mcp/IMcpLlmApplication.ts +0 -10
  54. package/src/structures/mcp/IMcpLlmFunction.ts +0 -19
@@ -17,13 +17,15 @@ export function execute<Model extends ILlmSchema.Model>(executor: Partial<IAgent
17
17
 
18
18
  // FUNCTIONS ARE NOT LISTED YET
19
19
  if (ctx.ready() === false) {
20
- if (executor?.initialize === null) {
20
+ if (executor?.initialize !== true && typeof executor?.initialize !== "function") {
21
21
  await ctx.initialize();
22
22
  }
23
23
  else {
24
24
  histories.push(
25
25
  ...(await (
26
- executor?.initialize ?? initialize
26
+ typeof executor?.initialize === "function"
27
+ ? executor.initialize
28
+ : initialize
27
29
  )(ctx)),
28
30
  );
29
31
  if (ctx.ready() === false) {
@@ -63,11 +65,15 @@ export function execute<Model extends ILlmSchema.Model>(executor: Partial<IAgent
63
65
  const executes: AgenticaExecuteHistory<Model>[] = prompts.filter(
64
66
  prompt => prompt.type === "execute",
65
67
  );
66
- histories.push(
67
- ...(await (
68
- executor?.describe ?? describe
69
- )(ctx, executes)),
70
- );
68
+ if (executor?.describe !== null && executor?.describe !== false) {
69
+ histories.push(
70
+ ...(await (
71
+ typeof executor?.describe === "function"
72
+ ? executor.describe
73
+ : describe
74
+ )(ctx, executes)),
75
+ );
76
+ }
71
77
  if (executes.length === 0 || ctx.stack.length === 0) {
72
78
  break;
73
79
  }
@@ -1,3 +1,4 @@
1
+ import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
1
2
  import type {
2
3
  IHttpConnection,
3
4
  IHttpLlmApplication,
@@ -6,10 +7,9 @@ import type {
6
7
  ILlmApplication,
7
8
  ILlmFunction,
8
9
  ILlmSchema,
10
+ IMcpLlmApplication,
9
11
  } from "@samchon/openapi";
10
12
 
11
- import type { IMcpLlmApplication } from "./mcp/IMcpLlmApplication";
12
-
13
13
  /**
14
14
  * Controller of the Agentica Agent.
15
15
  *
@@ -29,7 +29,7 @@ import type { IMcpLlmApplication } from "./mcp/IMcpLlmApplication";
29
29
  export type IAgenticaController<Model extends ILlmSchema.Model> =
30
30
  | IAgenticaController.IHttp<Model>
31
31
  | IAgenticaController.IClass<Model>
32
- | IAgenticaController.IMcp;
32
+ | IAgenticaController.IMcp<Model>;
33
33
 
34
34
  export namespace IAgenticaController {
35
35
  /**
@@ -122,7 +122,12 @@ export namespace IAgenticaController {
122
122
  /**
123
123
  * MCP Server controller.
124
124
  */
125
- export interface IMcp extends IBase<"mcp", IMcpLlmApplication> { }
125
+ export interface IMcp<Model extends ILlmSchema.Model> extends IBase<"mcp", IMcpLlmApplication<Model>> {
126
+ /**
127
+ * MCP client for connection.
128
+ */
129
+ client: Client;
130
+ }
126
131
 
127
132
  interface IBase<Protocol, Application> {
128
133
  /**
@@ -49,15 +49,17 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
49
49
  * conversate with the user.
50
50
  *
51
51
  * By the way, if you wanna skip the `initialize` agent, you can
52
- * do it by configuring the {@link IAgenticaConfig.executor} as
53
- * `null` value. In that case, the `initialize` agent will never be
54
- * called, and {@link Agentica} just starts from the {@link select}
55
- * agent.
52
+ * do it by configuring the {@link IAgenticaExecutor.initialize} as
53
+ * `undefined`, `false` or `null` value. In that case, the `initialize`
54
+ * agent will never be called, and {@link Agentica} just starts from the
55
+ * {@link select} agent.
56
56
  *
57
57
  * @param ctx Context of the agent
58
58
  * @returns List of prompts generated by the initializer
59
+ * @default false
59
60
  */
60
61
  initialize:
62
+ | boolean
61
63
  | null
62
64
  | ((ctx: AgenticaContext<Model>) => Promise<AgenticaHistory<Model>[]>);
63
65
 
@@ -124,14 +126,20 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
124
126
  * `Describe` agent explains the results of the function callings
125
127
  * to the user as markdown content.
126
128
  *
129
+ * If you configure this property as `false` or `null`, the describer
130
+ * agent will never be used.
131
+ *
127
132
  * @param ctx Context of the agent
128
133
  * @param executes List of function calling results
129
134
  * @returns List of prompts generated by the describer
130
135
  */
131
- describe: (
132
- ctx: AgenticaContext<Model>,
133
- executes: AgenticaExecuteHistory<Model>[],
134
- ) => Promise<AgenticaHistory<Model>[]>;
136
+ describe:
137
+ | boolean
138
+ | null
139
+ | ((
140
+ ctx: AgenticaContext<Model>,
141
+ executes: AgenticaExecuteHistory<Model>[],
142
+ ) => Promise<AgenticaHistory<Model>[]>);
135
143
 
136
144
  /**
137
145
  * Function canceler agent.
@@ -52,12 +52,18 @@ export interface IMicroAgenticaExecutor<Model extends ILlmSchema.Model> {
52
52
  * `Describe` agent explains the results of the function callings
53
53
  * to the user as markdown content.
54
54
  *
55
+ * If you configure this property as `false` or `null`, the describer
56
+ * agent never be used.
57
+ *
55
58
  * @param ctx Context of the agent
56
59
  * @param executes List of function calling results
57
60
  * @returns List of prompts generated by the describer
58
61
  */
59
- describe: (
60
- ctx: MicroAgenticaContext<Model>,
61
- executes: AgenticaExecuteHistory<Model>[],
62
- ) => Promise<MicroAgenticaHistory<Model>[]>;
62
+ describe:
63
+ | boolean
64
+ | null
65
+ | ((
66
+ ctx: MicroAgenticaContext<Model>,
67
+ executes: AgenticaExecuteHistory<Model>[],
68
+ ) => Promise<MicroAgenticaHistory<Model>[]>);
63
69
  }
@@ -1,3 +1 @@
1
- export * from "./IMcpLlmApplication";
2
- export * from "./IMcpLlmFunction";
3
1
  export * from "./IMcpLlmTransportProps";
@@ -1,18 +0,0 @@
1
- import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
- import type { IMcpLlmApplication } from "../structures/mcp";
3
- /**
4
- * Create an MCP LLM application instance with type assertion.
5
- *
6
- * Create an {@link IMcpLlmApplication} instance which represents
7
- * an MCP (Model Context Protocol) LLM application.
8
- *
9
- * @param props Properties to create the MCP LLM application instance
10
- * @param props.name Name of the MCP implementation.
11
- * @param props.url URL of the MCP server.
12
- * @param props.version Describes version of an MCP implementation.
13
- * @returns MCP LLM application instance
14
- * @author Samchon
15
- */
16
- export declare function assertMcpLlmApplication(props: {
17
- client: Client;
18
- }): Promise<IMcpLlmApplication>;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.assertMcpLlmApplication = assertMcpLlmApplication;
46
- /**
47
- * Create an MCP LLM application instance with type assertion.
48
- *
49
- * Create an {@link IMcpLlmApplication} instance which represents
50
- * an MCP (Model Context Protocol) LLM application.
51
- *
52
- * @param props Properties to create the MCP LLM application instance
53
- * @param props.name Name of the MCP implementation.
54
- * @param props.url URL of the MCP server.
55
- * @param props.version Describes version of an MCP implementation.
56
- * @returns MCP LLM application instance
57
- * @author Samchon
58
- */
59
- function assertMcpLlmApplication(props) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- // for peerDependencies
62
- const { ListToolsResultSchema } = yield Promise.resolve().then(() => __importStar(require("@modelcontextprotocol/sdk/types.js")));
63
- const toolList = yield props.client.request({ method: "tools/list" }, ListToolsResultSchema);
64
- return {
65
- functions: toolList.tools.map(tool => ({
66
- name: tool.name,
67
- description: tool.description,
68
- parameters: tool.inputSchema,
69
- })),
70
- client: props.client,
71
- };
72
- });
73
- }
74
- //# sourceMappingURL=assertMcpLlmApplication.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertMcpLlmApplication.js","sourceRoot":"","sources":["../../src/functional/assertMcpLlmApplication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,0DAeC;AA5BD;;;;;;;;;;;;GAYG;AACH,SAAsB,uBAAuB,CAAC,KAE7C;;QACC,uBAAuB;QACvB,MAAM,EAAE,qBAAqB,EAAE,GAAG,wDAAa,oCAAoC,GAAC,CAAC;QAErF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,qBAAqB,CAAC,CAAC;QAC7F,OAAO;YACL,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACrC,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,UAAU,EAAE,IAAI,CAAC,WAAW;aAC7B,CAAC,CAAC;YACH,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC;IACJ,CAAC;CAAA"}
@@ -1,9 +0,0 @@
1
- import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
- import type { IMcpLlmFunction } from "./IMcpLlmFunction";
3
- /**
4
- * MCP LLM application.
5
- */
6
- export interface IMcpLlmApplication {
7
- client: Client;
8
- functions: IMcpLlmFunction[];
9
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IMcpLlmApplication.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IMcpLlmApplication.js","sourceRoot":"","sources":["../../../src/structures/mcp/IMcpLlmApplication.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
1
- /**
2
- * MCP LLM function.
3
- */
4
- export interface IMcpLlmFunction {
5
- /**
6
- * Name of the function.
7
- */
8
- name: string;
9
- /**
10
- * Description of the function.
11
- */
12
- description?: string;
13
- /**
14
- * Parameters of the function.
15
- */
16
- parameters: object;
17
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IMcpLlmFunction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IMcpLlmFunction.js","sourceRoot":"","sources":["../../../src/structures/mcp/IMcpLlmFunction.ts"],"names":[],"mappings":""}
@@ -1,32 +0,0 @@
1
- import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
-
3
- import type { IMcpLlmApplication } from "../structures/mcp";
4
- /**
5
- * Create an MCP LLM application instance with type assertion.
6
- *
7
- * Create an {@link IMcpLlmApplication} instance which represents
8
- * an MCP (Model Context Protocol) LLM application.
9
- *
10
- * @param props Properties to create the MCP LLM application instance
11
- * @param props.name Name of the MCP implementation.
12
- * @param props.url URL of the MCP server.
13
- * @param props.version Describes version of an MCP implementation.
14
- * @returns MCP LLM application instance
15
- * @author Samchon
16
- */
17
- export async function assertMcpLlmApplication(props: {
18
- client: Client;
19
- }): Promise<IMcpLlmApplication> {
20
- // for peerDependencies
21
- const { ListToolsResultSchema } = await import("@modelcontextprotocol/sdk/types.js");
22
-
23
- const toolList = await props.client.request({ method: "tools/list" }, ListToolsResultSchema);
24
- return {
25
- functions: toolList.tools.map(tool => ({
26
- name: tool.name,
27
- description: tool.description,
28
- parameters: tool.inputSchema,
29
- })),
30
- client: props.client,
31
- };
32
- }
@@ -1,10 +0,0 @@
1
- import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
-
3
- import type { IMcpLlmFunction } from "./IMcpLlmFunction";
4
- /**
5
- * MCP LLM application.
6
- */
7
- export interface IMcpLlmApplication {
8
- client: Client;
9
- functions: IMcpLlmFunction[];
10
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * MCP LLM function.
3
- */
4
- export interface IMcpLlmFunction {
5
- /**
6
- * Name of the function.
7
- */
8
- name: string;
9
-
10
- /**
11
- * Description of the function.
12
- */
13
- description?: string;
14
-
15
- /**
16
- * Parameters of the function.
17
- */
18
- parameters: object;
19
- }