@console-agent/agent 1.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/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # @console-agent/agent
2
+
3
+ > Drop `console.agent(...)` anywhere in your code to execute agentic workflows — as easy as `console.log()`
4
+
5
+ [![npm](https://img.shields.io/npm/v/@console-agent/agent)](https://www.npmjs.com/package/@console-agent/agent)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Why?
9
+
10
+ - **Agents are too complicated.** Langchain requires 100+ lines of boilerplate.
11
+ - **Wrong abstraction layer.** Existing tools are for chat apps, not runtime utilities.
12
+ - **console.agent is the jQuery of agents.** Simple API, powerful capabilities.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ bun add @console-agent/agent @ai-sdk/google
18
+ # or
19
+ npm install @console-agent/agent @ai-sdk/google
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import '@console-agent/agent';
26
+
27
+ // That's it! console.agent is now available everywhere.
28
+
29
+ // Fire-and-forget (default) — never blocks your app
30
+ console.agent("analyze this error", error);
31
+
32
+ // Blocking mode — await for structured results
33
+ const result = await console.agent("validate email format", email);
34
+ if (!result.success) throw new Error(result.summary);
35
+
36
+ // Persona shortcuts
37
+ console.agent.security("check for SQL injection", userInput);
38
+ console.agent.debug("why is this slow?", { duration, query });
39
+ console.agent.architect("review this API design", endpoint);
40
+ ```
41
+
42
+ ## Configuration
43
+
44
+ ```typescript
45
+ import { init } from '@console-agent/agent';
46
+
47
+ init({
48
+ apiKey: process.env.GEMINI_API_KEY, // Or set GEMINI_API_KEY env var
49
+ model: 'gemini-2.5-flash-lite', // Default (fast & cheap)
50
+ persona: 'general', // 'debugger' | 'security' | 'architect' | 'general'
51
+ mode: 'fire-and-forget', // 'fire-and-forget' | 'blocking'
52
+ timeout: 10000, // ms
53
+
54
+ budget: {
55
+ maxCallsPerDay: 100,
56
+ maxTokensPerCall: 8000,
57
+ costCapDaily: 1.00, // USD
58
+ },
59
+
60
+ anonymize: true, // Auto-strip secrets/PII
61
+ localOnly: false, // Disable cloud tools
62
+ dryRun: false, // Log without calling API
63
+ logLevel: 'info', // 'silent' | 'errors' | 'info' | 'debug'
64
+ });
65
+ ```
66
+
67
+ > **Zero config works!** Just set `GEMINI_API_KEY` env var and import the package.
68
+
69
+ ## Models
70
+
71
+ | Model | Use Case | Default |
72
+ |-------|----------|---------|
73
+ | `gemini-2.5-flash-lite` | Fast, cheap, general purpose | ✅ |
74
+ | `gemini-3-flash-preview` | High thinking, complex reasoning | |
75
+
76
+ ```typescript
77
+ // Use high-thinking model for complex tasks
78
+ const result = await console.agent(
79
+ "design optimal database schema",
80
+ requirements,
81
+ {
82
+ model: 'gemini-3-flash-preview',
83
+ thinking: { level: 'high', includeThoughts: true },
84
+ }
85
+ );
86
+ console.log(result.reasoning); // Agent's thought process
87
+ ```
88
+
89
+ ## Personas
90
+
91
+ Personas auto-detect from prompt keywords, or set explicitly:
92
+
93
+ | Persona | Icon | Auto-detects | System Role |
94
+ |---------|------|--------------|-------------|
95
+ | `security` | 🛡️ | "injection", "xss", "vulnerability" | OWASP security expert |
96
+ | `debugger` | 🐛 | "slow", "error", "optimize" | Senior debugging expert |
97
+ | `architect` | 🏗️ | "design", "architecture", "schema" | Principal engineer |
98
+ | `general` | 🔍 | (default fallback) | Full-stack senior engineer |
99
+
100
+ ## Built-in Tools
101
+
102
+ Google's built-in tools are enabled per-persona:
103
+
104
+ - **code_execution** — Run Python in sandbox (math, algorithms, data transforms)
105
+ - **google_search** — Real-time search grounding with source attribution
106
+ - **file_analysis** — PDF, images, video processing
107
+
108
+ ```typescript
109
+ // Explicit tool selection
110
+ console.agent(
111
+ "research this company",
112
+ { domain: "acme.com" },
113
+ { tools: ['google_search', 'code_execution'] }
114
+ );
115
+ ```
116
+
117
+ ## Return Type
118
+
119
+ When awaited, `console.agent()` returns a structured `AgentResult`:
120
+
121
+ ```typescript
122
+ interface AgentResult {
123
+ success: boolean; // Overall task success
124
+ summary: string; // Human-readable conclusion
125
+ reasoning?: string; // Agent's thought process
126
+ data: Record<string, any>; // Structured findings
127
+ actions: string[]; // Tools used / steps taken
128
+ confidence: number; // 0-1 confidence score
129
+ metadata: {
130
+ model: string;
131
+ tokensUsed: number;
132
+ latencyMs: number;
133
+ toolCalls: ToolCall[];
134
+ cached: boolean;
135
+ };
136
+ }
137
+ ```
138
+
139
+ ## Console Output
140
+
141
+ ```
142
+ [AGENT] 🛡️ Security audit Complete
143
+ [AGENT] ├─ ✓ HIGH RISK: SQL injection detected in user input
144
+ [AGENT] ├─ Tool: google_search
145
+ [AGENT] ├─ vulnerability: SQL Injection via unsanitized input
146
+ [AGENT] ├─ fix: Use parameterized queries
147
+ [AGENT] └─ confidence: 0.94 | 247ms | 156 tokens
148
+ ```
149
+
150
+ ## Safety & Privacy
151
+
152
+ ```typescript
153
+ init({
154
+ // Auto-strips API keys, emails, IPs, secrets before sending
155
+ anonymize: true,
156
+
157
+ // Disable all cloud tools (code execution, search)
158
+ localOnly: true,
159
+
160
+ // Safety filters
161
+ safetySettings: [
162
+ { category: 'HARM_CATEGORY_DANGEROUS_CONTENT', threshold: 'BLOCK_MEDIUM_AND_ABOVE' },
163
+ ],
164
+ });
165
+ ```
166
+
167
+ ## Budget Controls
168
+
169
+ Hard limits prevent cost explosion:
170
+
171
+ ```typescript
172
+ init({
173
+ budget: {
174
+ maxCallsPerDay: 100, // Rate limit
175
+ maxTokensPerCall: 8000, // Per-call cap
176
+ costCapDaily: 1.00, // Hard daily USD cap
177
+ },
178
+ });
179
+ ```
180
+
181
+ ## Use Cases
182
+
183
+ ```typescript
184
+ // 🛡️ Security auditing
185
+ console.agent.security("check for SQL injection", userInput);
186
+
187
+ // 🐛 Debugging
188
+ console.agent.debug("why is this slow?", { duration, query, cacheHit });
189
+
190
+ // 📊 Data validation
191
+ const result = await console.agent("validate this batch meets schema", records);
192
+
193
+ // 🏗️ Architecture review
194
+ console.agent.architect("review this API design", { endpoint, handler });
195
+
196
+ // 🔢 Mathematical reasoning
197
+ const calc = await console.agent("calculate optimal batch size", metrics,
198
+ { tools: ['code_execution'] }
199
+ );
200
+ ```
201
+
202
+ ## Development
203
+
204
+ ```bash
205
+ bun install # Install dependencies
206
+ bun run build # Build ESM + CJS + types
207
+ bun run test # Run tests
208
+ bun run test:watch # Watch mode
209
+ bun run lint # Type check
210
+ ```
211
+
212
+ ## License
213
+
214
+ MIT © Pavel