@strav/brain 0.4.30 → 1.0.0-alpha.10
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/package.json +17 -20
- package/src/agent.ts +50 -75
- package/src/agent_result.ts +32 -0
- package/src/agent_runner.ts +63 -0
- package/src/brain_config.ts +80 -0
- package/src/brain_error.ts +29 -0
- package/src/brain_manager.ts +186 -123
- package/src/brain_provider.ts +91 -6
- package/src/define_tool.ts +42 -0
- package/src/index.ts +43 -42
- package/src/mcp_server.ts +47 -0
- package/src/provider.ts +83 -0
- package/src/providers/anthropic_provider.ts +435 -232
- package/src/thread.ts +99 -0
- package/src/tool.ts +28 -44
- package/src/tool_execution_error.ts +26 -0
- package/src/types.ts +164 -237
- package/CHANGELOG.md +0 -44
- package/README.md +0 -121
- package/src/helpers.ts +0 -1082
- package/src/mcp_toolbox.ts +0 -62
- package/src/memory/context_budget.ts +0 -120
- package/src/memory/index.ts +0 -17
- package/src/memory/memory_manager.ts +0 -168
- package/src/memory/semantic_memory.ts +0 -89
- package/src/memory/strategies/sliding_window.ts +0 -20
- package/src/memory/strategies/summarize.ts +0 -157
- package/src/memory/thread_store.ts +0 -56
- package/src/memory/token_counter.ts +0 -101
- package/src/memory/types.ts +0 -68
- package/src/providers/google_provider.ts +0 -496
- package/src/providers/openai_provider.ts +0 -569
- package/src/providers/openai_responses_provider.ts +0 -321
- package/src/utils/error_scrub.ts +0 -5
- package/src/utils/prompt.ts +0 -65
- package/src/utils/retry.ts +0 -104
- package/src/utils/schema.ts +0 -27
- package/src/utils/sse_parser.ts +0 -62
- package/src/workflow.ts +0 -199
- package/tsconfig.json +0 -5
package/CHANGELOG.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 0.2.12
|
|
4
|
-
|
|
5
|
-
### Added
|
|
6
|
-
|
|
7
|
-
- **GoogleProvider** — Support for Google's Gemini models
|
|
8
|
-
- Native Gemini API integration using `generativelanguage.googleapis.com`
|
|
9
|
-
- Support for completion, streaming, function calling, and embeddings
|
|
10
|
-
- Models: `gemini-2.0-flash`, `gemini-2.5-flash`, `gemini-3-pro-preview`
|
|
11
|
-
- Authentication via `x-goog-api-key` header
|
|
12
|
-
- Zero new dependencies — uses raw `fetch()` following existing patterns
|
|
13
|
-
- Comprehensive test suite with 29 tests covering all functionality
|
|
14
|
-
|
|
15
|
-
## 0.6.0
|
|
16
|
-
|
|
17
|
-
### Added
|
|
18
|
-
|
|
19
|
-
- **Memory management** — three-tier conversation memory system for long-running threads
|
|
20
|
-
- `thread.memory()` enables opt-in context window management
|
|
21
|
-
- **Working memory** — recent messages within token budget
|
|
22
|
-
- **Episodic memory** — LLM-generated summaries of compacted older messages
|
|
23
|
-
- **Semantic memory** — structured facts extracted from conversation, injected into system prompt
|
|
24
|
-
- `TokenCounter` — approximate token estimation per provider (~4 chars/token)
|
|
25
|
-
- `ContextBudget` — budget allocation across system prompt, summaries, facts, and working messages
|
|
26
|
-
- `MemoryManager` — orchestrates compaction and fact extraction
|
|
27
|
-
- `SemanticMemory` — in-memory fact store with `<known_facts>` prompt injection
|
|
28
|
-
- `SummarizeStrategy` — LLM-powered compaction with optional fact extraction
|
|
29
|
-
- `SlidingWindowStrategy` — drop oldest messages without summarization
|
|
30
|
-
- `InMemoryThreadStore` — default `ThreadStore` implementation for dev/testing
|
|
31
|
-
- `ThreadStore` interface — pluggable persistence (implement for database-backed storage)
|
|
32
|
-
- `BrainManager.useThreadStore()` — register a thread store for persistence
|
|
33
|
-
- `BrainManager.memoryConfig` / `BrainManager.threadStore` — accessors for memory configuration
|
|
34
|
-
- `thread.id()` — set thread identifier for persistence
|
|
35
|
-
- `thread.persist()` — enable auto-save to ThreadStore after each `send()`
|
|
36
|
-
- `thread.facts` / `thread.episodicSummary` — access memory state
|
|
37
|
-
- `thread.serializeMemory()` / `thread.restoreMemory()` — extended serialization with memory state
|
|
38
|
-
- `BrainConfig.memory` — optional `MemoryConfig` field for global memory settings
|
|
39
|
-
|
|
40
|
-
## 0.1.1
|
|
41
|
-
|
|
42
|
-
### Changed
|
|
43
|
-
|
|
44
|
-
- Applied consistent code formatting across all source files
|
package/README.md
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# @strav/brain
|
|
2
|
-
|
|
3
|
-
AI module for the [Strav](https://www.npmjs.com/package/@strav/core) framework. Provides a unified interface for AI providers with support for agents, threads, tool use, and multi-step workflows.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun add @strav/brain
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Requires `@strav/core` as a peer dependency.
|
|
12
|
-
|
|
13
|
-
## Providers
|
|
14
|
-
|
|
15
|
-
- **Anthropic** (Claude)
|
|
16
|
-
- **OpenAI** (GPT, also works with DeepSeek via custom `baseUrl`)
|
|
17
|
-
- **Google** (Gemini)
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import { brain } from '@strav/brain'
|
|
23
|
-
|
|
24
|
-
// One-shot chat
|
|
25
|
-
const response = await brain.chat('Explain quantum computing')
|
|
26
|
-
|
|
27
|
-
// Streaming
|
|
28
|
-
for await (const chunk of brain.stream('Write a poem')) {
|
|
29
|
-
process.stdout.write(chunk.text)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Structured output with Zod
|
|
33
|
-
import { z } from 'zod'
|
|
34
|
-
const result = await brain.generate('List 3 colors', {
|
|
35
|
-
schema: z.object({ colors: z.array(z.string()) }),
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// Embeddings
|
|
39
|
-
const vectors = await brain.embed('Hello world')
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Tools
|
|
43
|
-
|
|
44
|
-
Define tools that AI agents can use:
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
import { defineTool } from '@strav/brain'
|
|
48
|
-
import { z } from 'zod'
|
|
49
|
-
|
|
50
|
-
const searchTool = defineTool({
|
|
51
|
-
name: 'search',
|
|
52
|
-
description: 'Search the database',
|
|
53
|
-
parameters: z.object({ query: z.string() }),
|
|
54
|
-
execute: async ({ query }, context) => {
|
|
55
|
-
const userId = context?.userId
|
|
56
|
-
return await db.search(query, { userId })
|
|
57
|
-
},
|
|
58
|
-
})
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
The `execute` function receives two parameters:
|
|
62
|
-
- `args` - The parsed and validated tool arguments
|
|
63
|
-
- `context` - Optional context object passed from the agent runner
|
|
64
|
-
|
|
65
|
-
## Agents
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import { Agent, defineTool } from '@strav/brain'
|
|
69
|
-
|
|
70
|
-
class ResearchAgent extends Agent {
|
|
71
|
-
provider = 'anthropic'
|
|
72
|
-
model = 'claude-sonnet-4-20250514'
|
|
73
|
-
instructions = 'You are a research assistant.'
|
|
74
|
-
tools = [searchTool, summarizeTool]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Google Gemini agent
|
|
78
|
-
class GeminiResearchAgent extends Agent {
|
|
79
|
-
provider = 'google'
|
|
80
|
-
model = 'gemini-2.0-flash'
|
|
81
|
-
instructions = 'You are a research assistant powered by Gemini.'
|
|
82
|
-
tools = [searchTool, summarizeTool]
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Run agent with context
|
|
86
|
-
const runner = brain.agent(ResearchAgent)
|
|
87
|
-
runner.context({ userId: '123' }) // Pass context to tools
|
|
88
|
-
const result = await runner.input('Find info on Bun').run()
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Threads
|
|
92
|
-
|
|
93
|
-
Multi-turn conversations with serialization support:
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
const thread = brain.thread({ provider: 'anthropic', model: 'claude-sonnet-4-20250514' })
|
|
97
|
-
await thread.send('Hello')
|
|
98
|
-
await thread.send('Tell me more')
|
|
99
|
-
const saved = thread.serialize() // persist and restore later
|
|
100
|
-
|
|
101
|
-
// Google Gemini example
|
|
102
|
-
const geminiThread = brain.thread({ provider: 'google', model: 'gemini-2.0-flash' })
|
|
103
|
-
await geminiThread.send('Explain quantum computing')
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Workflows
|
|
107
|
-
|
|
108
|
-
Orchestrate multi-agent pipelines:
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
const workflow = brain.workflow()
|
|
112
|
-
.step('research', ResearchAgent)
|
|
113
|
-
.step('summarize', SummaryAgent)
|
|
114
|
-
.parallel('review', [FactCheckAgent, StyleAgent])
|
|
115
|
-
|
|
116
|
-
const result = await workflow.run('Analyze this topic')
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## License
|
|
120
|
-
|
|
121
|
-
MIT
|