mycto_agent 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 furioussoul
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 ADDED
@@ -0,0 +1,324 @@
1
+ # openagent-ai
2
+
3
+ A lightweight, extensible AI Agent framework with tool calling, streaming, and multi-provider support.
4
+
5
+ ## 30 Seconds Quick Start
6
+
7
+ ```typescript
8
+ import { anthropic } from 'openagent-ai'
9
+
10
+ const agent = anthropic('your-api-key')
11
+ const result = await agent.chat('Hello!')
12
+ console.log(result.text)
13
+ ```
14
+
15
+ That's it! The agent can read/write files, execute commands, search code, and more.
16
+
17
+ ## Features
18
+
19
+ - **Simple API**: One-line initialization, easy `chat()` and `stream()` methods
20
+ - **Built-in Tools**: File operations, bash execution, web fetching out of the box
21
+ - **Multi-Provider**: Works with Anthropic, OpenAI, Google, and OpenAI-compatible APIs
22
+ - **Extensible**: Custom tools, custom agents, pluggable storage
23
+ - **Streaming**: Real-time streaming of responses and tool execution
24
+ - **Agent Loop**: Automatic multi-step tool execution
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install openagent-ai
30
+ ```
31
+
32
+ ## Usage Examples
33
+
34
+ ### Basic Chat
35
+
36
+ ```typescript
37
+ import { anthropic } from 'openagent-ai'
38
+
39
+ const agent = anthropic(process.env.ANTHROPIC_API_KEY)
40
+
41
+ // Simple chat
42
+ const result = await agent.chat('List files in current directory')
43
+ console.log(result.text)
44
+ console.log(result.toolCalls) // See what tools were used
45
+ ```
46
+
47
+ ### Streaming
48
+
49
+ ```typescript
50
+ for await (const event of agent.stream('Create a hello.txt file')) {
51
+ if (event.type === 'text') process.stdout.write(event.text)
52
+ if (event.type === 'tool-start') console.log(`\nUsing: ${event.name}`)
53
+ if (event.type === 'done') console.log(`\nCost: $${event.result.cost}`)
54
+ }
55
+ ```
56
+
57
+ ### Use with OpenCode Config
58
+
59
+ If you have an `opencode.json` config file, you can load it directly:
60
+
61
+ ```typescript
62
+ import { OpenAgent, configureFromOpenCodeConfig } from 'openagent-ai'
63
+
64
+ // Load your opencode.json configuration
65
+ const config = require('./opencode.json')
66
+ configureFromOpenCodeConfig(config)
67
+
68
+ // Now use any configured provider
69
+ const agent = new OpenAgent({
70
+ provider: 'anthropic',
71
+ model: 'claude-opus-4.5',
72
+ })
73
+
74
+ const result = await agent.chat('Hello!')
75
+ ```
76
+
77
+ ## Built-in Tools
78
+
79
+ | Tool | Description |
80
+ |------|-------------|
81
+ | `read` | Read file contents |
82
+ | `write` | Create or overwrite files |
83
+ | `edit` | Edit files with smart text matching |
84
+ | `bash` | Execute shell commands |
85
+ | `glob` | Find files by pattern |
86
+ | `grep` | Search file contents with regex |
87
+ | `webfetch` | Fetch web content |
88
+ | `question` | Ask user for input |
89
+
90
+ ## Provider Setup
91
+
92
+ ### Anthropic (Recommended)
93
+
94
+ ```typescript
95
+ import { anthropic } from 'openagent-ai'
96
+
97
+ // Direct API
98
+ const agent = anthropic('sk-ant-xxx')
99
+
100
+ // With proxy/custom endpoint
101
+ const agent = new OpenAgent({
102
+ provider: 'anthropic',
103
+ apiKey: 'your-key',
104
+ baseURL: 'https://your-proxy.com/v1', // optional
105
+ model: 'claude-opus-4.5',
106
+ })
107
+ ```
108
+
109
+ ### OpenAI
110
+
111
+ ```typescript
112
+ import { openai } from 'openagent-ai'
113
+ const agent = openai('sk-xxx', 'gpt-4o')
114
+ ```
115
+
116
+ ### Google Gemini
117
+
118
+ ```typescript
119
+ import { google } from 'openagent-ai'
120
+ const agent = google('your-api-key', 'gemini-1.5-pro')
121
+ ```
122
+
123
+ ### OpenAI-Compatible APIs (Together, Groq, DeepSeek, etc.)
124
+
125
+ ```typescript
126
+ import { OpenAgent } from 'openagent-ai'
127
+
128
+ // Together AI
129
+ const agent = new OpenAgent({
130
+ provider: 'openai',
131
+ apiKey: process.env.TOGETHER_API_KEY,
132
+ baseURL: 'https://api.together.xyz/v1',
133
+ model: 'meta-llama/Llama-3-70b-chat-hf',
134
+ })
135
+
136
+ // Groq
137
+ const agent = new OpenAgent({
138
+ provider: 'openai',
139
+ apiKey: process.env.GROQ_API_KEY,
140
+ baseURL: 'https://api.groq.com/openai/v1',
141
+ model: 'llama-3.1-70b-versatile',
142
+ })
143
+
144
+ // DeepSeek
145
+ const agent = new OpenAgent({
146
+ provider: 'openai',
147
+ apiKey: process.env.DEEPSEEK_API_KEY,
148
+ baseURL: 'https://api.deepseek.com/v1',
149
+ model: 'deepseek-chat',
150
+ })
151
+
152
+ // ZhipuAI (GLM)
153
+ const agent = new OpenAgent({
154
+ provider: 'openai',
155
+ apiKey: process.env.ZHIPU_API_KEY,
156
+ baseURL: 'https://open.bigmodel.cn/api/paas/v4',
157
+ model: 'glm-4',
158
+ })
159
+
160
+ // Local Ollama
161
+ const agent = new OpenAgent({
162
+ provider: 'openai',
163
+ apiKey: 'not-needed',
164
+ baseURL: 'http://localhost:11434/v1',
165
+ model: 'llama3',
166
+ })
167
+ ```
168
+
169
+ ## Advanced Configuration
170
+
171
+ ### Full Options
172
+
173
+ ```typescript
174
+ const agent = new OpenAgent({
175
+ // Provider settings
176
+ provider: 'anthropic', // 'anthropic' | 'openai' | 'google'
177
+ apiKey: 'your-api-key',
178
+ baseURL: 'https://custom.api/v1', // optional proxy
179
+ model: 'claude-sonnet-4-20250514',
180
+ headers: { 'X-Custom': 'value' }, // optional headers
181
+
182
+ // Behavior settings
183
+ mode: 'build', // 'plan' (read-only) | 'build' (full access)
184
+ maxSteps: 10, // max tool execution rounds
185
+ temperature: 0.7,
186
+ maxOutputTokens: 4096,
187
+ workingDirectory: '/path/to/dir',
188
+
189
+ // Custom tools
190
+ tools: [myCustomTool],
191
+ useBuiltinTools: true, // default: true
192
+ })
193
+ ```
194
+
195
+ ### Custom Tools
196
+
197
+ ```typescript
198
+ import { OpenAgent, defineTool } from 'openagent-ai'
199
+ import { z } from 'zod'
200
+
201
+ const calculator = defineTool({
202
+ id: 'calculator',
203
+ description: 'Perform math calculations',
204
+ parameters: z.object({
205
+ expression: z.string().describe('Math expression like "2 + 2"'),
206
+ }),
207
+ execute: async (args) => ({
208
+ title: 'Calculation',
209
+ output: `Result: ${eval(args.expression)}`,
210
+ }),
211
+ })
212
+
213
+ const agent = new OpenAgent({
214
+ provider: 'anthropic',
215
+ apiKey: 'your-key',
216
+ tools: [calculator],
217
+ })
218
+ ```
219
+
220
+ ### Custom System Prompt
221
+
222
+ ```typescript
223
+ const agent = new OpenAgent({
224
+ provider: 'anthropic',
225
+ apiKey: 'your-key',
226
+ agent: {
227
+ name: 'code-reviewer',
228
+ systemPrompt: `You are an expert code reviewer.
229
+ Focus on: code quality, security, performance.`,
230
+ allowedTools: ['read', 'grep', 'glob'], // optional: restrict tools
231
+ },
232
+ })
233
+ ```
234
+
235
+ ### Session Management
236
+
237
+ ```typescript
238
+ // Chat returns sessionId for continuation
239
+ const result1 = await agent.chat('Read package.json')
240
+ console.log(result1.sessionId)
241
+
242
+ // Continue same conversation
243
+ const result2 = await agent.chat('What version?', {
244
+ sessionId: result1.sessionId
245
+ })
246
+
247
+ // Or use fluent API
248
+ const result3 = await agent
249
+ .continueSession(result1.sessionId)
250
+ .chat('Summarize it')
251
+
252
+ // Start fresh session
253
+ const result4 = await agent.newSession().chat('New topic')
254
+ ```
255
+
256
+ ## Agent Modes
257
+
258
+ - **`build`** (default): Full access - can read, write, execute
259
+ - **`plan`**: Read-only - can only read files and search
260
+
261
+ ```typescript
262
+ // Start in plan mode
263
+ const agent = new OpenAgent({ mode: 'plan' })
264
+
265
+ // Switch to build mode when ready
266
+ agent.setMode('build')
267
+ ```
268
+
269
+ ## Examples
270
+
271
+ See the [examples/](./examples/) directory:
272
+
273
+ ```bash
274
+ # Basic usage
275
+ npx tsx examples/simple.ts
276
+
277
+ # Custom tools
278
+ npx tsx examples/advanced.ts
279
+
280
+ # Test different providers
281
+ npx tsx examples/test-providers.ts
282
+ npx tsx examples/test-providers.ts anthropic --tools
283
+ ```
284
+
285
+ ## API Reference
286
+
287
+ ### ChatResult
288
+
289
+ ```typescript
290
+ interface ChatResult {
291
+ text: string // Final response text
292
+ toolCalls: ToolCall[] // Tools that were called
293
+ usage: TokenUsage // { input, output }
294
+ cost: number // Estimated cost in USD
295
+ finishReason: string // 'stop', 'tool_use', etc.
296
+ sessionId: string // For continuing conversation
297
+ }
298
+ ```
299
+
300
+ ### StreamEvent
301
+
302
+ ```typescript
303
+ type StreamEvent =
304
+ | { type: 'text'; text: string }
305
+ | { type: 'tool-start'; name: string; input: object }
306
+ | { type: 'tool-end'; name: string; output: string }
307
+ | { type: 'done'; result: ChatResult }
308
+ | { type: 'error'; error: Error }
309
+ ```
310
+
311
+ ## Documentation
312
+
313
+ - [Architecture](./ARCHITECTURE.md) - System design
314
+ - [Roadmap](./ROADMAP.md) - Future plans
315
+ - [Contributing](./CONTRIBUTING.md) - How to contribute
316
+
317
+ ## License
318
+
319
+ MIT
320
+
321
+ ## Links
322
+
323
+ - [GitHub](https://github.com/furioussoul/OpenAgent)
324
+ - [npm](https://www.npmjs.com/package/openagent-ai)