@agentica/vector-selector 0.43.3 → 0.44.0-dev.20260313-2
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.
- package/LICENSE +21 -21
- package/README.md +218 -218
- package/lib/index.mjs +28 -28
- package/lib/index.mjs.map +1 -1
- package/lib/select.js +5 -5
- package/lib/strategy/sqlite.strategy.js +14 -14
- package/lib/tools.js +29 -29
- package/package.json +4 -5
- package/src/extract_query.ts +51 -51
- package/src/index.ts +67 -67
- package/src/select.ts +212 -212
- package/src/strategy/index.ts +2 -2
- package/src/strategy/postgres.strategy.ts +116 -116
- package/src/strategy/sqlite.strategy.ts +123 -123
- package/src/tools.ts +99 -99
- package/src/utils.test.ts +357 -357
- package/src/utils.ts +123 -123
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Wrtn Technologies
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Wrtn Technologies
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,218 +1,218 @@
|
|
|
1
|
-
# Agentica, AI Function Calling Framework
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
<!-- Github/NPM Badges -->
|
|
6
|
-
<p align="center">
|
|
7
|
-
<a href="https://github.com/wrtnlabs/agentica/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License"/></a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/@agentica/core"><img src="https://img.shields.io/npm/v/@agentica/core.svg" alt="NPM Version"/></a>
|
|
9
|
-
<a href="https://www.npmjs.com/package/@agentica/core"><img src="https://img.shields.io/npm/dm/@agentica/core.svg" alt="NPM Downloads"/></a>
|
|
10
|
-
<a href="https://dormoshe.io/newsletters/373"><img src="https://img.shields.io/badge/DorMoshe%20Newsletter-Top%20%236%20of%201K-orange?style=flat&logo=rss" alt="Newsletter Top #6"/></a>
|
|
11
|
-
<a href="https://github.com/wrtnlabs/agentica/actions?query=workflow%3Abuild"><img src="https://github.com/wrtnlabs/agentica/workflows/build/badge.svg" alt="Build Status"/></a>
|
|
12
|
-
</p>
|
|
13
|
-
|
|
14
|
-
<!-- Youtube + Discord -->
|
|
15
|
-
<p align="center">
|
|
16
|
-
<a href="https://www.youtube.com/@wrtnlabs">
|
|
17
|
-
<img src="https://img.shields.io/badge/YouTube%20Tutorial-0d1117?style=social&logo=youtube" alt="YouTube"/>
|
|
18
|
-
</a>
|
|
19
|
-
|
|
20
|
-
<a href="https://discord.gg/aMhRmzkqCx">
|
|
21
|
-
<img src="https://img.shields.io/badge/Discord-0d1117?style=social&logo=discord" alt="Discord"/>
|
|
22
|
-
</a>
|
|
23
|
-
</p>
|
|
24
|
-
|
|
25
|
-
<p align="center">
|
|
26
|
-
<a href="https://www.bloomberg.com/news/videos/2025-03-31/wtrn-on-series-b-funding-growth-strategy-video">
|
|
27
|
-
<img src="https://wrtnlabs.io/agentica/images/badges/fund-raising-news-202503.svg" />
|
|
28
|
-
</a>
|
|
29
|
-
|
|
30
|
-
<a href="https://github.com/wrtnlabs">
|
|
31
|
-
<img src="https://wrtnlabs.io/agentica/images/badges/open-source-mission.svg" />
|
|
32
|
-
</a>
|
|
33
|
-
</p>
|
|
34
|
-
|
|
35
|
-
Agentic AI framework specialized in AI Function Calling.
|
|
36
|
-
|
|
37
|
-
Don't be afraid of AI agent development. Just list functions from three protocols below. This is everything you should do for AI agent development.
|
|
38
|
-
|
|
39
|
-
- TypeScript Class
|
|
40
|
-
- Swagger/OpenAPI Document
|
|
41
|
-
- MCP (Model Context Protocol) Server
|
|
42
|
-
|
|
43
|
-
Wanna make an e-commerce agent? Bring in e-commerce functions. Need a newspaper agent? Get API functions from the newspaper company. Just prepare any functions that you need, then it becomes an AI agent.
|
|
44
|
-
|
|
45
|
-
Are you a TypeScript developer? Then you're already an AI developer. Familiar with backend development? You're already well-versed in AI development. Anyone who can make functions can make AI agents.
|
|
46
|
-
|
|
47
|
-
<!-- eslint-skip -->
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
|
|
51
|
-
import { Agentica, assertHttpController } from "@agentica/core";
|
|
52
|
-
import OpenAI from "openai";
|
|
53
|
-
import typia from "typia";
|
|
54
|
-
|
|
55
|
-
import { MobileFileSystem } from "./services/MobileFileSystem";
|
|
56
|
-
|
|
57
|
-
const agent = new Agentica({
|
|
58
|
-
vendor: {
|
|
59
|
-
api: new OpenAI({ apiKey: "********" }),
|
|
60
|
-
model: "gpt-4o-mini",
|
|
61
|
-
},
|
|
62
|
-
controllers: [
|
|
63
|
-
// functions from TypeScript class
|
|
64
|
-
typia.llm.controller<MobileFileSystem>(
|
|
65
|
-
"filesystem",
|
|
66
|
-
new MobileFileSystem(),
|
|
67
|
-
),
|
|
68
|
-
// functions from Swagger/OpenAPI
|
|
69
|
-
assertHttpController({
|
|
70
|
-
name: "shopping",
|
|
71
|
-
model: "chatgpt",
|
|
72
|
-
document: await fetch(
|
|
73
|
-
"https://shopping-be.wrtn.ai/editor/swagger.json",
|
|
74
|
-
).then(r => r.json()),
|
|
75
|
-
connection: {
|
|
76
|
-
host: "https://shopping-be.wrtn.ai",
|
|
77
|
-
headers: { Authorization: "Bearer ********" },
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
80
|
-
],
|
|
81
|
-
});
|
|
82
|
-
await agent.conversate("I wanna buy MacBook Pro");
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## 📦 Setup
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
$ npx agentica start <directory>
|
|
90
|
-
|
|
91
|
-
----------------------------------------
|
|
92
|
-
Agentica Setup Wizard
|
|
93
|
-
----------------------------------------
|
|
94
|
-
? Package Manager (use arrow keys)
|
|
95
|
-
> npm
|
|
96
|
-
pnpm
|
|
97
|
-
yarn (berry is not supported)
|
|
98
|
-
? Project Type
|
|
99
|
-
NodeJS Agent Server
|
|
100
|
-
> NestJS Agent Server
|
|
101
|
-
React Client Application
|
|
102
|
-
Standalone Application
|
|
103
|
-
? Embedded Controllers (multi-selectable)
|
|
104
|
-
(none)
|
|
105
|
-
Google Calendar
|
|
106
|
-
Google News
|
|
107
|
-
> Github
|
|
108
|
-
Reddit
|
|
109
|
-
Slack
|
|
110
|
-
...
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
The setup wizard helps you create a new project tailored to your needs.
|
|
114
|
-
|
|
115
|
-
For reference, when selecting a project type, any option other than "Standalone Application" will implement the [WebSocket Protocol](https://wrtnlabs.io/agentica/docs/websocket/) for client-server communication.
|
|
116
|
-
|
|
117
|
-
For comprehensive setup instructions, visit our [Getting Started](https://wrtnlabs.io/agentica/docs/) guide.
|
|
118
|
-
|
|
119
|
-
## 💻 Playground
|
|
120
|
-
|
|
121
|
-
Experience Agentica firsthand through our [interactive playground](https://wrtnlabs.io/agentica/playground) before installing.
|
|
122
|
-
|
|
123
|
-
Our demonstrations showcase the power and simplicity of Agentica's function calling capabilities across different integration methods.
|
|
124
|
-
|
|
125
|
-
- [TypeScript Class](https://wrtnlabs.io/agentica/playground/bbs)
|
|
126
|
-
- [Swagger/OpenAPI Document](https://wrtnlabs.io/agentica/playground/uploader)
|
|
127
|
-
- [Enterprise E-commerce Agent](https://wrtnlabs.io/agentica/playground/shopping)
|
|
128
|
-
|
|
129
|
-

|
|
130
|
-
|
|
131
|
-
<!--
|
|
132
|
-
@todo this section would be changed after making tutorial playground
|
|
133
|
-
-->
|
|
134
|
-
|
|
135
|
-
## 📚 Documentation Resources
|
|
136
|
-
|
|
137
|
-
Find comprehensive resources at our [official website](https://wrtnlabs.io/agentica).
|
|
138
|
-
|
|
139
|
-
- [Home](https://wrtnlabs.io/agentica)
|
|
140
|
-
- [Guide Documents](https://wrtnlabs.io/agentica/docs)
|
|
141
|
-
- [Setup](https://wrtnlabs.io/agentica/docs/setup/cli/)
|
|
142
|
-
- [Concepts](https://wrtnlabs.io/agentica/docs/concepts/function-calling/)
|
|
143
|
-
- [Core Library](https://wrtnlabs.io/agentica/docs/core/)
|
|
144
|
-
- [WebSocket Protocol](https://wrtnlabs.io/agentica/docs/websocket/)
|
|
145
|
-
- [Plugin Modules](https://wrtnlabs.io/agentica/docs/plugins/benchmark/)
|
|
146
|
-
- [Tutorial](https://wrtnlabs.io/agentica/tutorial)
|
|
147
|
-
- [Productivity](https://wrtnlabs.io/agentica/tutorial/productivity/arxiv/)
|
|
148
|
-
- [Coding](https://wrtnlabs.io/agentica/tutorial/coding/file-system/)
|
|
149
|
-
- [React Native](https://wrtnlabs.io/agentica/tutorial/react-native/sms/)
|
|
150
|
-
- [Enterprise](https://wrtnlabs.io/agentica/tutorial/enterprise/shopping/)
|
|
151
|
-
- [API Documents](https://wrtnlabs.io/agentica/api)
|
|
152
|
-
- [Youtube](https://www.youtube.com/@wrtnlabs)
|
|
153
|
-
- [Paper](https://wrtnlabs.io/agentica/paper)
|
|
154
|
-
|
|
155
|
-
https://github.com/user-attachments/assets/2f2a4cdc-6cf1-4304-b82d-04a8ed0be0dd
|
|
156
|
-
|
|
157
|
-
> Tutorial Videos: https://www.youtube.com/@wrtnlabs
|
|
158
|
-
|
|
159
|
-
## 🌟 Why Agentica?
|
|
160
|
-
|
|
161
|
-
```mermaid
|
|
162
|
-
flowchart
|
|
163
|
-
subgraph "JSON Schema Specification"
|
|
164
|
-
schemav4("JSON Schema v4 ~ v7") --upgrades--> emended[["OpenAPI v3.1 (emended)"]]
|
|
165
|
-
schema2910("JSON Schema 2019-03") --upgrades--> emended
|
|
166
|
-
schema2020("JSON Schema 2020-12") --emends--> emended
|
|
167
|
-
end
|
|
168
|
-
subgraph "Agentica"
|
|
169
|
-
emended --"Artificial Intelligence"--> fc{{"AI Function Calling"}}
|
|
170
|
-
fc --"OpenAI"--> chatgpt("ChatGPT")
|
|
171
|
-
fc --"Google"--> gemini("Gemini")
|
|
172
|
-
fc --"Anthropic"--> claude("Claude")
|
|
173
|
-
fc --"High-Flyer"--> deepseek("DeepSeek")
|
|
174
|
-
fc --"Meta"--> llama("Llama")
|
|
175
|
-
chatgpt --"3.1"--> custom(["Custom JSON Schema"])
|
|
176
|
-
gemini --"3.0"--> custom(["Custom JSON Schema"])
|
|
177
|
-
claude --"3.1"--> standard(["Standard JSON Schema"])
|
|
178
|
-
deepseek --"3.1"--> standard
|
|
179
|
-
llama --"3.1"--> standard
|
|
180
|
-
end
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
Agentica enhances AI function calling by the following strategies:
|
|
184
|
-
|
|
185
|
-
- [**Compiler Driven Development**](https://wrtnlabs.io/agentica/docs/concepts/compiler-driven-development): constructs function calling schema automatically by compiler skills without hand-writing.
|
|
186
|
-
- [**JSON Schema Conversion**](https://wrtnlabs.io/agentica/docs/core/vendor/#schema-specification): automatically handles specification differences between LLM vendors, ensuring seamless integration regardless of your chosen AI model.
|
|
187
|
-
- [**Validation Feedback**](https://wrtnlabs.io/agentica/docs/concepts/function-calling#validation-feedback): detects and corrects AI mistakes in argument composition, dramatically reducing errors and improving reliability.
|
|
188
|
-
- [**Selector Agent**](https://wrtnlabs.io/agentica/docs/concepts/function-calling#orchestration-strategy): filtering candidate functions to minimize context usage, optimize performance, and reduce token consumption.
|
|
189
|
-
|
|
190
|
-
Thanks to these innovations, Agentica makes AI function calling easier, safer, and more accurate than before. Development becomes more intuitive since you only need to prepare functions relevant to your specific use case, and scaling your agent's capabilities is as simple as adding or removing functions.
|
|
191
|
-
|
|
192
|
-
In 2023, when OpenAI announced function calling, many predicted that function calling-driven AI development would become the mainstream. However, in reality, due to the difficulty and instability of function calling, the trend in AI development became agent workflow. Agent workflow, which is inflexible and must be created for specific purposes, has conquered the AI agent ecosystem.
|
|
193
|
-
|
|
194
|
-
By the way, as Agentica has resolved the difficulty and instability problems of function calling, the time has come to embrace function-driven AI development once again.
|
|
195
|
-
|
|
196
|
-
| Type | Workflow | Vanilla Function Calling | Agentica Function Calling |
|
|
197
|
-
| ----------- | ------------- | ------------------------ | ------------------------- |
|
|
198
|
-
| Purpose | ❌ Specific | 🟢 General | 🟢 General |
|
|
199
|
-
| Difficulty | ❌ Difficult | ❌ Difficult | 🟢 Easy |
|
|
200
|
-
| Stability | 🟢 Stable | ❌ Unstable | 🟢 Stable |
|
|
201
|
-
| Flexibility | ❌ Inflexible | 🟢 Flexible | 🟢 Flexible |
|
|
202
|
-
|
|
203
|
-
## 💬 Community & Support
|
|
204
|
-
|
|
205
|
-
For support, questions, or to provide feedback, join our Discord community:
|
|
206
|
-
|
|
207
|
-
[](https://discord.gg/aMhRmzkqCx)
|
|
208
|
-
|
|
209
|
-
## ⚖️ License
|
|
210
|
-
|
|
211
|
-
Agentica is open-source and available under the [MIT License](https://github.com/wrtnlabs/agentica/blob/master/LICENSE).
|
|
212
|
-
|
|
213
|
-
<p align="center">
|
|
214
|
-
<img src="https://github.com/user-attachments/assets/ecd0b82e-bfb7-4eb5-ae97-75be0cb22f10" alt="Wrtn Labs Logo" />
|
|
215
|
-
</p>
|
|
216
|
-
<div align="center">
|
|
217
|
-
Agentica is maintained by <a href="https://wrtnlabs.io">Wrtn Technologies</a> — Empowering developers to transform TypeScript functions and OpenAPI specs into powerful AI agents.
|
|
218
|
-
</div>
|
|
1
|
+
# Agentica, AI Function Calling Framework
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
<!-- Github/NPM Badges -->
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://github.com/wrtnlabs/agentica/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License"/></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@agentica/core"><img src="https://img.shields.io/npm/v/@agentica/core.svg" alt="NPM Version"/></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@agentica/core"><img src="https://img.shields.io/npm/dm/@agentica/core.svg" alt="NPM Downloads"/></a>
|
|
10
|
+
<a href="https://dormoshe.io/newsletters/373"><img src="https://img.shields.io/badge/DorMoshe%20Newsletter-Top%20%236%20of%201K-orange?style=flat&logo=rss" alt="Newsletter Top #6"/></a>
|
|
11
|
+
<a href="https://github.com/wrtnlabs/agentica/actions?query=workflow%3Abuild"><img src="https://github.com/wrtnlabs/agentica/workflows/build/badge.svg" alt="Build Status"/></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<!-- Youtube + Discord -->
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://www.youtube.com/@wrtnlabs">
|
|
17
|
+
<img src="https://img.shields.io/badge/YouTube%20Tutorial-0d1117?style=social&logo=youtube" alt="YouTube"/>
|
|
18
|
+
</a>
|
|
19
|
+
|
|
20
|
+
<a href="https://discord.gg/aMhRmzkqCx">
|
|
21
|
+
<img src="https://img.shields.io/badge/Discord-0d1117?style=social&logo=discord" alt="Discord"/>
|
|
22
|
+
</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<a href="https://www.bloomberg.com/news/videos/2025-03-31/wtrn-on-series-b-funding-growth-strategy-video">
|
|
27
|
+
<img src="https://wrtnlabs.io/agentica/images/badges/fund-raising-news-202503.svg" />
|
|
28
|
+
</a>
|
|
29
|
+
|
|
30
|
+
<a href="https://github.com/wrtnlabs">
|
|
31
|
+
<img src="https://wrtnlabs.io/agentica/images/badges/open-source-mission.svg" />
|
|
32
|
+
</a>
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
Agentic AI framework specialized in AI Function Calling.
|
|
36
|
+
|
|
37
|
+
Don't be afraid of AI agent development. Just list functions from three protocols below. This is everything you should do for AI agent development.
|
|
38
|
+
|
|
39
|
+
- TypeScript Class
|
|
40
|
+
- Swagger/OpenAPI Document
|
|
41
|
+
- MCP (Model Context Protocol) Server
|
|
42
|
+
|
|
43
|
+
Wanna make an e-commerce agent? Bring in e-commerce functions. Need a newspaper agent? Get API functions from the newspaper company. Just prepare any functions that you need, then it becomes an AI agent.
|
|
44
|
+
|
|
45
|
+
Are you a TypeScript developer? Then you're already an AI developer. Familiar with backend development? You're already well-versed in AI development. Anyone who can make functions can make AI agents.
|
|
46
|
+
|
|
47
|
+
<!-- eslint-skip -->
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
|
|
51
|
+
import { Agentica, assertHttpController } from "@agentica/core";
|
|
52
|
+
import OpenAI from "openai";
|
|
53
|
+
import typia from "typia";
|
|
54
|
+
|
|
55
|
+
import { MobileFileSystem } from "./services/MobileFileSystem";
|
|
56
|
+
|
|
57
|
+
const agent = new Agentica({
|
|
58
|
+
vendor: {
|
|
59
|
+
api: new OpenAI({ apiKey: "********" }),
|
|
60
|
+
model: "gpt-4o-mini",
|
|
61
|
+
},
|
|
62
|
+
controllers: [
|
|
63
|
+
// functions from TypeScript class
|
|
64
|
+
typia.llm.controller<MobileFileSystem>(
|
|
65
|
+
"filesystem",
|
|
66
|
+
new MobileFileSystem(),
|
|
67
|
+
),
|
|
68
|
+
// functions from Swagger/OpenAPI
|
|
69
|
+
assertHttpController({
|
|
70
|
+
name: "shopping",
|
|
71
|
+
model: "chatgpt",
|
|
72
|
+
document: await fetch(
|
|
73
|
+
"https://shopping-be.wrtn.ai/editor/swagger.json",
|
|
74
|
+
).then(r => r.json()),
|
|
75
|
+
connection: {
|
|
76
|
+
host: "https://shopping-be.wrtn.ai",
|
|
77
|
+
headers: { Authorization: "Bearer ********" },
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
await agent.conversate("I wanna buy MacBook Pro");
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 📦 Setup
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
$ npx agentica start <directory>
|
|
90
|
+
|
|
91
|
+
----------------------------------------
|
|
92
|
+
Agentica Setup Wizard
|
|
93
|
+
----------------------------------------
|
|
94
|
+
? Package Manager (use arrow keys)
|
|
95
|
+
> npm
|
|
96
|
+
pnpm
|
|
97
|
+
yarn (berry is not supported)
|
|
98
|
+
? Project Type
|
|
99
|
+
NodeJS Agent Server
|
|
100
|
+
> NestJS Agent Server
|
|
101
|
+
React Client Application
|
|
102
|
+
Standalone Application
|
|
103
|
+
? Embedded Controllers (multi-selectable)
|
|
104
|
+
(none)
|
|
105
|
+
Google Calendar
|
|
106
|
+
Google News
|
|
107
|
+
> Github
|
|
108
|
+
Reddit
|
|
109
|
+
Slack
|
|
110
|
+
...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The setup wizard helps you create a new project tailored to your needs.
|
|
114
|
+
|
|
115
|
+
For reference, when selecting a project type, any option other than "Standalone Application" will implement the [WebSocket Protocol](https://wrtnlabs.io/agentica/docs/websocket/) for client-server communication.
|
|
116
|
+
|
|
117
|
+
For comprehensive setup instructions, visit our [Getting Started](https://wrtnlabs.io/agentica/docs/) guide.
|
|
118
|
+
|
|
119
|
+
## 💻 Playground
|
|
120
|
+
|
|
121
|
+
Experience Agentica firsthand through our [interactive playground](https://wrtnlabs.io/agentica/playground) before installing.
|
|
122
|
+
|
|
123
|
+
Our demonstrations showcase the power and simplicity of Agentica's function calling capabilities across different integration methods.
|
|
124
|
+
|
|
125
|
+
- [TypeScript Class](https://wrtnlabs.io/agentica/playground/bbs)
|
|
126
|
+
- [Swagger/OpenAPI Document](https://wrtnlabs.io/agentica/playground/uploader)
|
|
127
|
+
- [Enterprise E-commerce Agent](https://wrtnlabs.io/agentica/playground/shopping)
|
|
128
|
+
|
|
129
|
+

|
|
130
|
+
|
|
131
|
+
<!--
|
|
132
|
+
@todo this section would be changed after making tutorial playground
|
|
133
|
+
-->
|
|
134
|
+
|
|
135
|
+
## 📚 Documentation Resources
|
|
136
|
+
|
|
137
|
+
Find comprehensive resources at our [official website](https://wrtnlabs.io/agentica).
|
|
138
|
+
|
|
139
|
+
- [Home](https://wrtnlabs.io/agentica)
|
|
140
|
+
- [Guide Documents](https://wrtnlabs.io/agentica/docs)
|
|
141
|
+
- [Setup](https://wrtnlabs.io/agentica/docs/setup/cli/)
|
|
142
|
+
- [Concepts](https://wrtnlabs.io/agentica/docs/concepts/function-calling/)
|
|
143
|
+
- [Core Library](https://wrtnlabs.io/agentica/docs/core/)
|
|
144
|
+
- [WebSocket Protocol](https://wrtnlabs.io/agentica/docs/websocket/)
|
|
145
|
+
- [Plugin Modules](https://wrtnlabs.io/agentica/docs/plugins/benchmark/)
|
|
146
|
+
- [Tutorial](https://wrtnlabs.io/agentica/tutorial)
|
|
147
|
+
- [Productivity](https://wrtnlabs.io/agentica/tutorial/productivity/arxiv/)
|
|
148
|
+
- [Coding](https://wrtnlabs.io/agentica/tutorial/coding/file-system/)
|
|
149
|
+
- [React Native](https://wrtnlabs.io/agentica/tutorial/react-native/sms/)
|
|
150
|
+
- [Enterprise](https://wrtnlabs.io/agentica/tutorial/enterprise/shopping/)
|
|
151
|
+
- [API Documents](https://wrtnlabs.io/agentica/api)
|
|
152
|
+
- [Youtube](https://www.youtube.com/@wrtnlabs)
|
|
153
|
+
- [Paper](https://wrtnlabs.io/agentica/paper)
|
|
154
|
+
|
|
155
|
+
https://github.com/user-attachments/assets/2f2a4cdc-6cf1-4304-b82d-04a8ed0be0dd
|
|
156
|
+
|
|
157
|
+
> Tutorial Videos: https://www.youtube.com/@wrtnlabs
|
|
158
|
+
|
|
159
|
+
## 🌟 Why Agentica?
|
|
160
|
+
|
|
161
|
+
```mermaid
|
|
162
|
+
flowchart
|
|
163
|
+
subgraph "JSON Schema Specification"
|
|
164
|
+
schemav4("JSON Schema v4 ~ v7") --upgrades--> emended[["OpenAPI v3.1 (emended)"]]
|
|
165
|
+
schema2910("JSON Schema 2019-03") --upgrades--> emended
|
|
166
|
+
schema2020("JSON Schema 2020-12") --emends--> emended
|
|
167
|
+
end
|
|
168
|
+
subgraph "Agentica"
|
|
169
|
+
emended --"Artificial Intelligence"--> fc{{"AI Function Calling"}}
|
|
170
|
+
fc --"OpenAI"--> chatgpt("ChatGPT")
|
|
171
|
+
fc --"Google"--> gemini("Gemini")
|
|
172
|
+
fc --"Anthropic"--> claude("Claude")
|
|
173
|
+
fc --"High-Flyer"--> deepseek("DeepSeek")
|
|
174
|
+
fc --"Meta"--> llama("Llama")
|
|
175
|
+
chatgpt --"3.1"--> custom(["Custom JSON Schema"])
|
|
176
|
+
gemini --"3.0"--> custom(["Custom JSON Schema"])
|
|
177
|
+
claude --"3.1"--> standard(["Standard JSON Schema"])
|
|
178
|
+
deepseek --"3.1"--> standard
|
|
179
|
+
llama --"3.1"--> standard
|
|
180
|
+
end
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Agentica enhances AI function calling by the following strategies:
|
|
184
|
+
|
|
185
|
+
- [**Compiler Driven Development**](https://wrtnlabs.io/agentica/docs/concepts/compiler-driven-development): constructs function calling schema automatically by compiler skills without hand-writing.
|
|
186
|
+
- [**JSON Schema Conversion**](https://wrtnlabs.io/agentica/docs/core/vendor/#schema-specification): automatically handles specification differences between LLM vendors, ensuring seamless integration regardless of your chosen AI model.
|
|
187
|
+
- [**Validation Feedback**](https://wrtnlabs.io/agentica/docs/concepts/function-calling#validation-feedback): detects and corrects AI mistakes in argument composition, dramatically reducing errors and improving reliability.
|
|
188
|
+
- [**Selector Agent**](https://wrtnlabs.io/agentica/docs/concepts/function-calling#orchestration-strategy): filtering candidate functions to minimize context usage, optimize performance, and reduce token consumption.
|
|
189
|
+
|
|
190
|
+
Thanks to these innovations, Agentica makes AI function calling easier, safer, and more accurate than before. Development becomes more intuitive since you only need to prepare functions relevant to your specific use case, and scaling your agent's capabilities is as simple as adding or removing functions.
|
|
191
|
+
|
|
192
|
+
In 2023, when OpenAI announced function calling, many predicted that function calling-driven AI development would become the mainstream. However, in reality, due to the difficulty and instability of function calling, the trend in AI development became agent workflow. Agent workflow, which is inflexible and must be created for specific purposes, has conquered the AI agent ecosystem.
|
|
193
|
+
|
|
194
|
+
By the way, as Agentica has resolved the difficulty and instability problems of function calling, the time has come to embrace function-driven AI development once again.
|
|
195
|
+
|
|
196
|
+
| Type | Workflow | Vanilla Function Calling | Agentica Function Calling |
|
|
197
|
+
| ----------- | ------------- | ------------------------ | ------------------------- |
|
|
198
|
+
| Purpose | ❌ Specific | 🟢 General | 🟢 General |
|
|
199
|
+
| Difficulty | ❌ Difficult | ❌ Difficult | 🟢 Easy |
|
|
200
|
+
| Stability | 🟢 Stable | ❌ Unstable | 🟢 Stable |
|
|
201
|
+
| Flexibility | ❌ Inflexible | 🟢 Flexible | 🟢 Flexible |
|
|
202
|
+
|
|
203
|
+
## 💬 Community & Support
|
|
204
|
+
|
|
205
|
+
For support, questions, or to provide feedback, join our Discord community:
|
|
206
|
+
|
|
207
|
+
[](https://discord.gg/aMhRmzkqCx)
|
|
208
|
+
|
|
209
|
+
## ⚖️ License
|
|
210
|
+
|
|
211
|
+
Agentica is open-source and available under the [MIT License](https://github.com/wrtnlabs/agentica/blob/master/LICENSE).
|
|
212
|
+
|
|
213
|
+
<p align="center">
|
|
214
|
+
<img src="https://github.com/user-attachments/assets/ecd0b82e-bfb7-4eb5-ae97-75be0cb22f10" alt="Wrtn Labs Logo" />
|
|
215
|
+
</p>
|
|
216
|
+
<div align="center">
|
|
217
|
+
Agentica is maintained by <a href="https://wrtnlabs.io">Wrtn Technologies</a> — Empowering developers to transform TypeScript functions and OpenAPI specs into powerful AI agents.
|
|
218
|
+
</div>
|
package/lib/index.mjs
CHANGED
|
@@ -85,13 +85,13 @@ async function extractQuery(ctx) {
|
|
|
85
85
|
}
|
|
86
86
|
return utils.ChatGptCompletionMessageUtil.merge(await utils.StreamUtil.readAll(completionStream.value));
|
|
87
87
|
})();
|
|
88
|
-
const queries = completion.choices[0]?.message.tool_calls?.filter(
|
|
88
|
+
const queries = completion.choices[0]?.message.tool_calls?.filter(tc => tc.type === "function").flatMap(v => {
|
|
89
89
|
const arg = JSON.parse(v.function.arguments);
|
|
90
90
|
if (!Array.isArray(arg.query_list)) {
|
|
91
91
|
return [];
|
|
92
92
|
}
|
|
93
|
-
return arg.query_list.map(
|
|
94
|
-
})
|
|
93
|
+
return arg.query_list.map(v => v.query);
|
|
94
|
+
}) ?? [];
|
|
95
95
|
return queries;
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -129,15 +129,15 @@ async function selectFunction(props) {
|
|
|
129
129
|
}
|
|
130
130
|
},
|
|
131
131
|
tools: [ Tools.select_functions ]
|
|
132
|
-
}).then(
|
|
132
|
+
}).then(async v => {
|
|
133
133
|
if (v.type === "none-stream") {
|
|
134
134
|
return v.value;
|
|
135
135
|
}
|
|
136
136
|
return utils.ChatGptCompletionMessageUtil.merge(await utils.StreamUtil.readAll(v.value));
|
|
137
|
-
})
|
|
138
|
-
const toolCalls = selectCompletion.choices.filter(
|
|
137
|
+
});
|
|
138
|
+
const toolCalls = selectCompletion.choices.filter(v => v.message.tool_calls != null);
|
|
139
139
|
if (toolCalls.length === 0) {
|
|
140
|
-
selectCompletion.choices.forEach(
|
|
140
|
+
selectCompletion.choices.forEach(v => {
|
|
141
141
|
if (v.message.content != null && v.message.content !== "") {
|
|
142
142
|
const event = factory.createAssistantMessageEvent({
|
|
143
143
|
stream: utils.toAsyncGenerator(v.message.content),
|
|
@@ -145,12 +145,12 @@ async function selectFunction(props) {
|
|
|
145
145
|
get: () => v.message.content,
|
|
146
146
|
join: async () => v.message.content
|
|
147
147
|
});
|
|
148
|
-
void ctx.dispatch(event).catch((
|
|
148
|
+
void ctx.dispatch(event).catch(() => {});
|
|
149
149
|
}
|
|
150
|
-
})
|
|
150
|
+
});
|
|
151
151
|
}
|
|
152
|
-
const failures = toolCalls.reduce((
|
|
153
|
-
cur.message.tool_calls?.filter(
|
|
152
|
+
const failures = toolCalls.reduce((acc, cur) => {
|
|
153
|
+
cur.message.tool_calls?.filter(tc => tc.type === "function").forEach(tc => {
|
|
154
154
|
const errors = [];
|
|
155
155
|
const arg = JSON.parse(tc.function.arguments);
|
|
156
156
|
if (!Array.isArray(arg)) {
|
|
@@ -161,7 +161,7 @@ async function selectFunction(props) {
|
|
|
161
161
|
}));
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
|
-
arg.forEach((
|
|
164
|
+
arg.forEach((v, idx) => {
|
|
165
165
|
if (v.reason == null || typeof v.reason !== "string") {
|
|
166
166
|
errors.push(JSON.stringify({
|
|
167
167
|
path: `$$input[${idx}].reason`,
|
|
@@ -176,7 +176,7 @@ async function selectFunction(props) {
|
|
|
176
176
|
value: v.function_name
|
|
177
177
|
}));
|
|
178
178
|
}
|
|
179
|
-
})
|
|
179
|
+
});
|
|
180
180
|
if (errors.length !== 0) {
|
|
181
181
|
acc.push({
|
|
182
182
|
id: tc.id,
|
|
@@ -187,9 +187,9 @@ async function selectFunction(props) {
|
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
-
})
|
|
190
|
+
});
|
|
191
191
|
return acc;
|
|
192
|
-
}
|
|
192
|
+
}, []);
|
|
193
193
|
if (failures.length !== 0) {
|
|
194
194
|
const feedback = [ ...prevFailures, ...failures ];
|
|
195
195
|
if (restRetry === 0) {
|
|
@@ -202,10 +202,10 @@ async function selectFunction(props) {
|
|
|
202
202
|
restRetry: restRetry - 1
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
-
toolCalls.forEach(
|
|
206
|
-
v.message.tool_calls.filter(
|
|
205
|
+
toolCalls.forEach(v => {
|
|
206
|
+
v.message.tool_calls.filter(tc => tc.type === "function").forEach(tc => {
|
|
207
207
|
const arg = JSON.parse(tc.function.arguments);
|
|
208
|
-
arg.function_list.forEach(
|
|
208
|
+
arg.function_list.forEach(v => {
|
|
209
209
|
const operation = ctx.operations.flat.get(v.function_name);
|
|
210
210
|
if (operation === undefined) {
|
|
211
211
|
return;
|
|
@@ -217,14 +217,14 @@ async function selectFunction(props) {
|
|
|
217
217
|
ctx.stack.push(selection);
|
|
218
218
|
void ctx.dispatch(factory.createSelectEvent({
|
|
219
219
|
selection
|
|
220
|
-
})).catch((
|
|
221
|
-
})
|
|
222
|
-
})
|
|
223
|
-
})
|
|
220
|
+
})).catch(() => {});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
function emendMessages(failures) {
|
|
227
|
-
return failures.flatMap(
|
|
227
|
+
return failures.flatMap(f => [ {
|
|
228
228
|
role: "assistant",
|
|
229
229
|
tool_calls: [ {
|
|
230
230
|
type: "function",
|
|
@@ -241,19 +241,19 @@ function emendMessages(failures) {
|
|
|
241
241
|
}, {
|
|
242
242
|
role: "system",
|
|
243
243
|
content: [ "You A.I. assistant has composed wrong typed arguments.", "", "Correct it at the next function calling." ].join("\n")
|
|
244
|
-
} ])
|
|
244
|
+
} ]);
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
function uniqBy(array, selector) {
|
|
248
248
|
const seen = new Set;
|
|
249
|
-
return array.filter(
|
|
249
|
+
return array.filter(item => {
|
|
250
250
|
const key = selector(item);
|
|
251
251
|
if (seen.has(key)) {
|
|
252
252
|
return false;
|
|
253
253
|
}
|
|
254
254
|
seen.add(key);
|
|
255
255
|
return true;
|
|
256
|
-
})
|
|
256
|
+
});
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
function BootAgenticaVectorSelector(props) {
|
|
@@ -267,7 +267,7 @@ function BootAgenticaVectorSelector(props) {
|
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
const queries = await extractQuery(ctx);
|
|
270
|
-
const toolList = await Promise.all(queries.map(
|
|
270
|
+
const toolList = await Promise.all(queries.map(async query => searchTool(ctx, query))).then(res => res.flat().map(v => {
|
|
271
271
|
const op = ctx.operations.flat.get(v.name);
|
|
272
272
|
if (op === undefined || op.protocol !== "http") {
|
|
273
273
|
return v;
|
|
@@ -278,7 +278,7 @@ function BootAgenticaVectorSelector(props) {
|
|
|
278
278
|
path: op.function.path,
|
|
279
279
|
tags: op.function.tags
|
|
280
280
|
};
|
|
281
|
-
}))
|
|
281
|
+
})).then(arr => uniqBy(arr, v => v.name));
|
|
282
282
|
if (toolList.length === 0) {
|
|
283
283
|
return;
|
|
284
284
|
}
|