@strav/brain 0.4.31 → 1.0.0-alpha.9

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 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