smart_brain 0.1.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7159ad731aa002ec432e8c9389954c0bcc6b526e5b513615860d82ed01d72424
4
- data.tar.gz: d589941e689323506ca1f8b0f580b6a56ddabfde6266b6c521f805a961f1eb5e
3
+ metadata.gz: 75c340badd56930942aa5962236b5fc850e2ecea1f8251feeaec57eda381c31c
4
+ data.tar.gz: 9e0acf383f25d23ccb2cc9b13287ec2acd0da3b92ddd9ed6709984f1c2391d76
5
5
  SHA512:
6
- metadata.gz: 84772ff685f99c49ee0220e3cf1b3e203b171dde4a3894a778c95083c1679d0078b510dc230201504f75fccca3cdddebe83463f9c7377429d5ecdf254cb96389
7
- data.tar.gz: 9253cfb3b3de9ac5ac3fd9ca066132aa587f236a36bc0ced080753a8c31be2e010ce9ce54e6e9416ec6b7b08063ecd31ef1ab2f78e65c00f1050bd69ec8c2972
6
+ metadata.gz: 3cf6e7380e1e0902b55d2b4ece8a1fceba73ad38523dd52ae964c422aa023f1557a7a8db3de9e3b73c75a5a1864dd53bb132018323b4b3f1ab819cc3e18ae5ee
7
+ data.tar.gz: ce0a1f93caa6f9cb1f22890da9dd751b2f1aa533d5dd70b0c26303d069c53f48007a8a0c6ca4363289201207dfa069af5c4b17b40fa0a169b996e8bcc3767294
data/README.en.md CHANGED
@@ -1,173 +1,173 @@
1
- # SmartBrain
2
-
3
- SmartBrain is an Agent Memory Runtime and Context Composer.
4
-
5
- Core responsibilities:
6
- - `commit_turn`: persist event truth and structured memory
7
- - `compose_context`: build minimal, sufficient context per turn
8
- - integrate with SmartRAG: SmartBrain handles conversation memory, SmartRAG handles resource retrieval
9
-
10
- ## Current Progress
11
-
12
- The repository now includes a runnable v0.1 flow with:
13
- - `commit_turn` / `compose_context` end-to-end pipeline
14
- - retention / consolidation / retrieval / composition policies
15
- - retrievers: exact + relational
16
- - fusion: dedupe, rule-based rerank, diversity, budget truncation
17
- - SmartRAG adapters: `NullClient`, `HttpClient`, `DirectClient`
18
- - traceability via `request_id` / `plan_id` / `context_id`
19
- - RSpec coverage (unit + integration + regression)
20
-
21
- ## Project Layout
22
-
23
- - `lib/smart_brain.rb`: public API
24
- - `lib/smart_brain/runtime.rb`: runtime orchestration
25
- - `lib/smart_brain/contracts/`: RetrievalPlan / EvidencePack / ContextPackage validation
26
- - `lib/smart_brain/observability/`: logs and metrics
27
- - `lib/smart_brain/event_store/`: event storage (in-memory currently)
28
- - `lib/smart_brain/memory_store/`: memory storage (in-memory currently)
29
- - `lib/smart_brain/retrievers/`: exact/relational retrievers
30
- - `lib/smart_brain/fusion/`: multi-source fusion
31
- - `lib/smart_brain/context_composer/`: context assembly
32
- - `lib/smart_brain/adapters/smart_rag/`: SmartRAG adapters
33
- - `config/brain.yml`: policy config
34
- - `example.rb`: SmartBrain + SmartAgent + SmartPrompt + SmartRAG demo
35
- - `docs/`: design and protocol documents
36
-
37
- ## Installation
38
-
39
- ```bash
40
- bundle install
41
- ```
42
-
43
- If you hit permission/shared-gem issues:
44
-
45
- ```bash
46
- bundle config set --local path 'vendor/bundle'
47
- bundle config set --local disable_shared_gems 'true'
48
- ```
49
-
50
- ## Quick Start (SmartBrain Only)
51
-
52
- ```ruby
53
- require_relative 'lib/smart_brain'
54
-
55
- SmartBrain.configure
56
-
57
- SmartBrain.commit_turn(
58
- session_id: 'demo',
59
- turn_events: {
60
- messages: [
61
- { role: 'user', content: 'Remember this: default DB is Postgres.' },
62
- { role: 'assistant', content: 'Saved.' }
63
- ],
64
- decisions: [
65
- { key: 'decision:smartbrain:storage', decision: 'Use Postgres by default' }
66
- ]
67
- }
68
- )
69
-
70
- context = SmartBrain.compose_context(
71
- session_id: 'demo',
72
- user_message: 'Continue and summarize key points'
73
- )
74
-
75
- puts context[:context_id]
76
- puts context.dig(:debug, :trace, :request_id)
77
- puts context.dig(:debug, :trace, :plan_id)
78
- ```
79
-
80
- ## SmartRAG Integration Options
81
-
82
- ### 1) NullClient (default)
83
-
84
- If no SmartRAG client is injected, resource evidence is empty.
85
-
86
- ### 2) HttpClient
87
-
88
- ```ruby
89
- transport = lambda do |plan, timeout_seconds:|
90
- {
91
- plan_id: 'p1',
92
- supports_language_filter: true,
93
- evidences: []
94
- }
95
- end
96
-
97
- client = SmartBrain::Adapters::SmartRag::HttpClient.new(transport: transport, timeout_seconds: 2)
98
- SmartBrain.configure(smart_rag_client: client)
99
- ```
100
-
101
- ### 3) DirectClient (used in `example.rb`)
102
-
103
- ```ruby
104
- require '/home/mlf/smart_ai/smart_rag/lib/smart_rag'
105
- require_relative 'lib/smart_brain/adapters/smart_rag/direct_client'
106
-
107
- rag_config = SmartRAG::Config.load('/home/mlf/smart_ai/smart_rag/config/smart_rag.yml')
108
- rag = SmartRAG::SmartRAG.new(rag_config)
109
- client = SmartBrain::Adapters::SmartRag::DirectClient.new(rag: rag)
110
-
111
- SmartBrain.configure(smart_rag_client: client)
112
- ```
113
-
114
- ## `example.rb` (Updated)
115
-
116
- The example demonstrates the real loop:
117
- 1. SmartBrain `compose_context`
118
- 2. SmartAgent calls SmartPrompt worker via `call_worker`
119
- 3. SmartBrain `commit_turn`
120
- 4. prints `evidence(memory/resource)` so you can verify SmartRAG participation
121
-
122
- Files used by the demo:
123
- - `config/example_agent.yml`
124
- - `config/example_llm.yml`
125
- - `agents/brain_assistant.rb`
126
- - `workers/brain_assistant.rb`
127
- - `templates/brain_assistant.erb`
128
-
129
- Run:
130
-
131
- ```bash
132
- bundle exec ruby example.rb
133
- ```
134
-
135
- ## Core API
136
-
137
- ### `SmartBrain.configure(config_path: nil, smart_rag_client: nil, clock: -> { Time.now.utc })`
138
- Initialize runtime and optionally inject a SmartRAG client.
139
-
140
- ### `SmartBrain.commit_turn(session_id:, turn_events:)`
141
- Persist events, extract memory, resolve conflicts, update summary.
142
-
143
- ### `SmartBrain.compose_context(session_id:, user_message:, agent_state: {})`
144
- Build a `ContextPackage` with planning and fused evidence.
145
-
146
- ### `SmartBrain.diagnostics`
147
- Return observability snapshot for compose/commit logs and metrics.
148
-
149
- ## Test
150
-
151
- ```bash
152
- rspec
153
- ```
154
-
155
- ## Troubleshooting
156
-
157
- ### 1) `cannot load such file -- sequel/extensions/pgvector`
158
- `example.rb` already applies compatibility handling (`Sequel.extension 'pgvector'` and strips `database.extensions` from DB connect config).
159
-
160
- ### 2) `Config file not found: config/llm_config.yml`
161
- `example.rb` injects `config_path: ./config/example_llm.yml` for SmartRAG EmbeddingService startup.
162
-
163
- ### 3) `ruby-lsp: not found`
164
- ```bash
165
- gem install --user-install ruby-lsp debug
166
- ```
167
- and ensure user gem `bin` is in `PATH`.
168
-
169
- ## Roadmap
170
-
171
- - migrate EventStore/MemoryStore from in-memory to Postgres-backed implementations
172
- - integrate real reranker/embedding models
173
- - improve SmartRAG ingest pipeline and cross-session evaluation tooling
1
+ # SmartBrain
2
+
3
+ SmartBrain is an Agent Memory Runtime and Context Composer.
4
+
5
+ Core responsibilities:
6
+ - `commit_turn`: persist event truth and structured memory
7
+ - `compose_context`: build minimal, sufficient context per turn
8
+ - integrate with SmartRAG: SmartBrain handles conversation memory, SmartRAG handles resource retrieval
9
+
10
+ ## Current Progress
11
+
12
+ The repository now includes a runnable v0.1 flow with:
13
+ - `commit_turn` / `compose_context` end-to-end pipeline
14
+ - retention / consolidation / retrieval / composition policies
15
+ - retrievers: exact + relational
16
+ - fusion: dedupe, rule-based rerank, diversity, budget truncation
17
+ - SmartRAG adapters: `NullClient`, `HttpClient`, `DirectClient`
18
+ - traceability via `request_id` / `plan_id` / `context_id`
19
+ - RSpec coverage (unit + integration + regression)
20
+
21
+ ## Project Layout
22
+
23
+ - `lib/smart_brain.rb`: public API
24
+ - `lib/smart_brain/runtime.rb`: runtime orchestration
25
+ - `lib/smart_brain/contracts/`: RetrievalPlan / EvidencePack / ContextPackage validation
26
+ - `lib/smart_brain/observability/`: logs and metrics
27
+ - `lib/smart_brain/event_store/`: event storage (in-memory currently)
28
+ - `lib/smart_brain/memory_store/`: memory storage (in-memory currently)
29
+ - `lib/smart_brain/retrievers/`: exact/relational retrievers
30
+ - `lib/smart_brain/fusion/`: multi-source fusion
31
+ - `lib/smart_brain/context_composer/`: context assembly
32
+ - `lib/smart_brain/adapters/smart_rag/`: SmartRAG adapters
33
+ - `config/brain.yml`: policy config
34
+ - `example.rb`: SmartBrain + SmartAgent + SmartPrompt + SmartRAG demo
35
+ - `docs/`: design and protocol documents
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ bundle install
41
+ ```
42
+
43
+ If you hit permission/shared-gem issues:
44
+
45
+ ```bash
46
+ bundle config set --local path 'vendor/bundle'
47
+ bundle config set --local disable_shared_gems 'true'
48
+ ```
49
+
50
+ ## Quick Start (SmartBrain Only)
51
+
52
+ ```ruby
53
+ require_relative 'lib/smart_brain'
54
+
55
+ SmartBrain.configure
56
+
57
+ SmartBrain.commit_turn(
58
+ session_id: 'demo',
59
+ turn_events: {
60
+ messages: [
61
+ { role: 'user', content: 'Remember this: default DB is Postgres.' },
62
+ { role: 'assistant', content: 'Saved.' }
63
+ ],
64
+ decisions: [
65
+ { key: 'decision:smartbrain:storage', decision: 'Use Postgres by default' }
66
+ ]
67
+ }
68
+ )
69
+
70
+ context = SmartBrain.compose_context(
71
+ session_id: 'demo',
72
+ user_message: 'Continue and summarize key points'
73
+ )
74
+
75
+ puts context[:context_id]
76
+ puts context.dig(:debug, :trace, :request_id)
77
+ puts context.dig(:debug, :trace, :plan_id)
78
+ ```
79
+
80
+ ## SmartRAG Integration Options
81
+
82
+ ### 1) NullClient (default)
83
+
84
+ If no SmartRAG client is injected, resource evidence is empty.
85
+
86
+ ### 2) HttpClient
87
+
88
+ ```ruby
89
+ transport = lambda do |plan, timeout_seconds:|
90
+ {
91
+ plan_id: 'p1',
92
+ supports_language_filter: true,
93
+ evidences: []
94
+ }
95
+ end
96
+
97
+ client = SmartBrain::Adapters::SmartRag::HttpClient.new(transport: transport, timeout_seconds: 2)
98
+ SmartBrain.configure(smart_rag_client: client)
99
+ ```
100
+
101
+ ### 3) DirectClient (used in `example.rb`)
102
+
103
+ ```ruby
104
+ require 'smart_rag'
105
+ require_relative 'lib/smart_brain/adapters/smart_rag/direct_client'
106
+
107
+ rag_config = SmartRAG::Config.load(ENV.fetch('SMARTRAG_CONFIG_PATH'))
108
+ rag = SmartRAG::SmartRAG.new(rag_config)
109
+ client = SmartBrain::Adapters::SmartRag::DirectClient.new(rag: rag)
110
+
111
+ SmartBrain.configure(smart_rag_client: client)
112
+ ```
113
+
114
+ ## `example.rb` (Updated)
115
+
116
+ The example demonstrates the real loop:
117
+ 1. SmartBrain `compose_context`
118
+ 2. SmartAgent calls SmartPrompt worker via `call_worker`
119
+ 3. SmartBrain `commit_turn`
120
+ 4. prints `evidence(memory/resource)` so you can verify SmartRAG participation
121
+
122
+ Files used by the demo:
123
+ - `config/example_agent.yml`
124
+ - `config/example_llm.yml`
125
+ - `agents/brain_assistant.rb`
126
+ - `workers/brain_assistant.rb`
127
+ - `templates/brain_assistant.erb`
128
+
129
+ Run:
130
+
131
+ ```bash
132
+ bundle exec ruby example.rb
133
+ ```
134
+
135
+ ## Core API
136
+
137
+ ### `SmartBrain.configure(config_path: nil, smart_rag_client: nil, clock: -> { Time.now.utc })`
138
+ Initialize runtime and optionally inject a SmartRAG client.
139
+
140
+ ### `SmartBrain.commit_turn(session_id:, turn_events:)`
141
+ Persist events, extract memory, resolve conflicts, update summary.
142
+
143
+ ### `SmartBrain.compose_context(session_id:, user_message:, agent_state: {})`
144
+ Build a `ContextPackage` with planning and fused evidence.
145
+
146
+ ### `SmartBrain.diagnostics`
147
+ Return observability snapshot for compose/commit logs and metrics.
148
+
149
+ ## Test
150
+
151
+ ```bash
152
+ rspec
153
+ ```
154
+
155
+ ## Troubleshooting
156
+
157
+ ### 1) `cannot load such file -- sequel/extensions/pgvector`
158
+ `example.rb` already applies compatibility handling (`Sequel.extension 'pgvector'` and strips `database.extensions` from DB connect config).
159
+
160
+ ### 2) `Config file not found: config/llm_config.yml`
161
+ `example.rb` injects `config_path: ./config/example_llm.yml` for SmartRAG EmbeddingService startup.
162
+
163
+ ### 3) `ruby-lsp: not found`
164
+ ```bash
165
+ gem install --user-install ruby-lsp debug
166
+ ```
167
+ and ensure user gem `bin` is in `PATH`.
168
+
169
+ ## Roadmap
170
+
171
+ - migrate EventStore/MemoryStore from in-memory to Postgres-backed implementations
172
+ - integrate real reranker/embedding models
173
+ - improve SmartRAG ingest pipeline and cross-session evaluation tooling