Skip to content

Commit 2674562

Browse files
committed
Update dependencies and introduce gemini-ipc crate for Inter-Process Communication
- Added the `ipc` crate to centralize IPC definitions and facilitate communication between various components. - Updated `Cargo.toml` files across multiple modules to include the new `ipc` dependency. - Refactored IPC-related code in the MCP and CLI modules to utilize the new `ipc` crate, improving code organization and maintainability. - Enhanced the README.md to document the new `gemini-ipc` features and its role in the architecture, including new daemons `HAPPE` and `IDA` that leverage IPC for communication.
1 parent a385f79 commit 2674562

20 files changed

Lines changed: 450 additions & 20 deletions

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HAPPE/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "happe"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
tokio = { version = "1", features = ["full"] }
10+
serde = { version = "1.0", features = ["derive"] }
11+
serde_json = "1.0"
12+
ipc = { path = "../ipc" }
13+
# Add LLM interaction crate (e.g., reqwest, llm-chain)
14+
# Add MCP client crate (if HAPPE needs to directly call MCP tools requested by LLM)
15+
# Add core crate dependency
16+
# core = { path = "../core" }
17+
18+
[[bin]]
19+
name = "happe-daemon"
20+
path = "src/main.rs"

HAPPE/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# HAPPE Crate (`@happe`)
2+
3+
## Overview
4+
5+
The `HAPPE` (Host Application Environment) crate implements the core host daemon responsible for managing interactions between the user, the main Large Language Model (LLM), and other system components like the Internal Dialogue App (`IDA`) and MCP Servers.
6+
7+
It acts as the primary execution environment, orchestrating the flow of information and commands based on user requests and LLM responses.
8+
9+
## Core Responsibilities
10+
11+
1. **User/Client Interface:** (Future) Provides the primary interface for user interaction, potentially through various means like APIs, WebSockets, or other front-ends (initially replacing the direct CLI usage).
12+
2. **LLM Interaction:** Manages the connection and communication with the main LLM, sending constructed prompts and receiving generated responses.
13+
3. **IDA Communication (IPC Client):**
14+
* Connects to the `IDA` daemon via Inter-Process Communication (IPC).
15+
* Sends the user's raw query to `IDA` before contacting the LLM to allow `IDA` to retrieve relevant memories.
16+
* Receives retrieved memories (or none) from `IDA`.
17+
* Constructs the final prompt for the LLM by **appending** the received memories to the **original user query**.
18+
* Asynchronously sends the complete conversation turn (original query, appended memories, LLM response) back to `IDA` for analysis and storage after the LLM interaction is complete.
19+
4. **MCP Tool Execution (LLM-Initiated):** If the main LLM decides to use an MCP Tool during its response generation, `HAPPE` is responsible for invoking the appropriate MCP Server (likely via the `@mcp` crate or direct MCP client logic) and returning the result to the LLM.
20+
5. **State Management:** Manages the immediate state required for the current interaction turn.
21+
22+
## Architecture
23+
24+
`HAPPE` is designed as a long-running daemon process. It communicates with `IDA` via IPC. Its primary workflow involves:
25+
26+
1. Receiving a user query.
27+
2. Querying `IDA` for contextual memories.
28+
3. Constructing the LLM prompt.
29+
4. Executing the LLM call.
30+
5. Handling any MCP tool calls requested by the LLM during generation.
31+
6. Returning the final response to the user/client.
32+
7. Asynchronously informing `IDA` about the completed turn for learning/memory storage.
33+
34+
```mermaid
35+
sequenceDiagram
36+
participant User/Client
37+
participant HAPPE (Daemon)
38+
participant IDA (Daemon via IPC)
39+
participant MemoryMCPServer
40+
participant OtherMCPServers
41+
participant MainLLM
42+
43+
User/Client->>+HAPPE: Sends Raw Query
44+
HAPPE->>+IDA: Send Raw Query [IPC Call]
45+
IDA->>+MemoryMCPServer: retrieve_memories()
46+
MemoryMCPServer-->>-IDA: Return Memories
47+
IDA-->>-HAPPE: Send Back Memories [IPC Response]
48+
HAPPE->>HAPPE: Construct Prompt = Query + Memories
49+
HAPPE->>+MainLLM: Send Prompt
50+
alt LLM needs MCP Tool
51+
MainLLM-->>HAPPE: Request Tool X
52+
HAPPE->>+OtherMCPServers: Execute Tool X
53+
OtherMCPServers-->>-HAPPE: Tool Result
54+
HAPPE-->>MainLLM: Provide Tool Result
55+
end
56+
MainLLM-->>-HAPPE: Receive Final LLM Response
57+
HAPPE-->>User/Client: Display Response
58+
HAPPE-)+IDA: Send Full Turn [Async IPC Call]
59+
IDA->>IDA: Process Turn for Storage
60+
deactivate HAPPE
61+
activate IDA
62+
IDA->>+MemoryMCPServer: store_memory()
63+
MemoryMCPServer-->>-IDA: Ack
64+
deactivate MemoryMCPServer
65+
deactivate IDA
66+
```
67+
68+
## Usage
69+
70+
This crate builds into the `happe-daemon` executable. Configuration details (LLM endpoints, IDA IPC address, MCP server details) will likely be managed via configuration files or environment variables.
71+
72+
```bash
73+
# Build
74+
cargo build --release
75+
76+
# Run (Example)
77+
./target/release/happe-daemon
78+
```
79+
80+
## Dependencies
81+
82+
* `tokio`: For asynchronous runtime.
83+
* `serde`, `serde_json`: For serialization/deserialization.
84+
* IPC Crate (e.g., `interprocess`): For communication with IDA.
85+
* LLM Client Crate: For interacting with the main LLM.
86+
* (Potentially) `@mcp` or MCP client logic: For handling LLM-initiated tool calls.
87+
* (Potentially) `@core`: For shared types or utilities.

HAPPE/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[tokio::main]
2+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
3+
println!("Starting HAPPE Daemon...");
4+
5+
// 1. Initialize IPC client to connect to IDA
6+
7+
// 2. Initialize connection to Main LLM
8+
9+
// 3. Initialize MCP Client logic (if needed for LLM-requested tools)
10+
11+
// 4. Start main loop (e.g., listening for user input/API requests)
12+
// - Receive user query
13+
// - Send query to IDA via IPC
14+
// - Receive memories from IDA via IPC
15+
// - Construct prompt (query + memories)
16+
// - Send prompt to Main LLM
17+
// - Receive response from Main LLM
18+
// - Send response to user/client
19+
// - Send turn info (query, memories, response) to IDA asynchronously via IPC
20+
21+
println!("HAPPE Daemon shutting down.");
22+
Ok(())
23+
}

IDA/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "ida"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
tokio = { version = "1", features = ["full"] }
10+
serde = { version = "1.0", features = ["derive"] }
11+
serde_json = "1.0"
12+
ipc = { path = "../ipc" }
13+
# Add MCP client crate (as IDA needs to call Memory MCP Server tools)
14+
# mcp = { path = "../mcp" }
15+
# Add core crate dependency
16+
# core = { path = "../core" }
17+
# Add embedding generation crate (if IDA handles this)
18+
# Add vector similarity search client (if needed beyond MCP calls)
19+
20+
[[bin]]
21+
name = "ida-daemon"
22+
path = "src/main.rs"

IDA/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# IDA Crate (`@ida`)
2+
3+
## Overview
4+
5+
The `IDA` (Internal Dialogue App) crate implements a background daemon responsible for managing persistent memory and potentially other background cognitive tasks for the main Host Application (`HAPPE`). It acts as a specialized service that enhances the context provided to the LLM and learns from interactions over time.
6+
7+
## Core Responsibilities
8+
9+
1. **IPC Server:** Listens for requests from the `HAPPE` daemon via Inter-Process Communication (IPC).
10+
2. **Memory Retrieval (Pre-computation):**
11+
* Receives the raw user query from `HAPPE`.
12+
* Uses its MCP client to call the `Memory MCP Server` (e.g., the one wrapping LanceDB) to retrieve relevant memories based on the query (likely using semantic search via embeddings).
13+
* Returns the retrieved memories (or an indication of none) back to `HAPPE` via IPC, allowing `HAPPE` to append them to the prompt.
14+
3. **Memory Storage (Post-computation - Asynchronous):**
15+
* Receives the full conversation turn details (original query, appended memories, LLM response) asynchronously from `HAPPE` via IPC after the turn is complete.
16+
* Analyzes this information to determine what new knowledge should be stored as memory.
17+
* (Potentially) Generates embeddings for the new memory candidates.
18+
* Uses its MCP client to call the `Memory MCP Server` to check if the candidate memory is a duplicate of existing memories (e.g., via similarity search).
19+
* If the memory is novel and relevant, uses its MCP client to instruct the `Memory MCP Server` to store the new memory.
20+
4. **Interaction with Memory Store:** Handles all direct interaction logic (via MCP calls) with the underlying memory persistence layer (e.g., LanceDB via its MCP Server).
21+
22+
## Architecture
23+
24+
`IDA` is designed as a long-running daemon process, communicating with `HAPPE` via IPC and with the `Memory MCP Server` via MCP.
25+
26+
Its primary functions are triggered by IPC calls from `HAPPE`:
27+
28+
* **Synchronous Request/Response for Retrieval:** When `HAPPE` gets a new query, it asks `IDA` for memories and waits for the response before proceeding.
29+
* **Asynchronous Notification for Storage:** After `HAPPE` completes an interaction turn, it sends the details to `IDA` and does not wait for a response, allowing `IDA` to process storage in the background.
30+
31+
```mermaid
32+
sequenceDiagram
33+
participant HAPPE (Daemon)
34+
participant IDA (Daemon via IPC)
35+
participant MemoryMCPServer
36+
37+
%% Retrieval Phase
38+
HAPPE->>+IDA: Send Raw Query [IPC Call]
39+
IDA->>+MemoryMCPServer: retrieve_memories(raw_query)
40+
MemoryMCPServer-->>-IDA: Return Relevant Memories
41+
IDA-->>-HAPPE: Send Back Memories [IPC Response]
42+
43+
%% Storage Phase (Triggered Later)
44+
HAPPE-)+IDA: Send Full Turn Info [Async IPC Call]
45+
activate IDA
46+
IDA->>IDA: Analyze Turn Data
47+
IDA->>IDA: Generate Embeddings (Optional)
48+
IDA->>+MemoryMCPServer: check_duplicates(candidate_memory)
49+
MemoryMCPServer-->>-IDA: Duplication Check Result
50+
alt Memory is Novel
51+
IDA->>+MemoryMCPServer: store_memory(new_memory)
52+
MemoryMCPServer-->>-IDA: Ack Storage
53+
end
54+
deactivate MemoryMCPServer
55+
deactivate IDA
56+
57+
```
58+
59+
## Usage
60+
61+
This crate builds into the `ida-daemon` executable. It needs to be running for `HAPPE` to function correctly with memory capabilities. Configuration (IPC address/path, Memory MCP Server details) will likely be managed via configuration files or environment variables.
62+
63+
```bash
64+
# Build
65+
cargo build --release
66+
67+
# Run (Example)
68+
./target/release/ida-daemon
69+
```
70+
71+
## Dependencies
72+
73+
* `tokio`: For asynchronous runtime.
74+
* `serde`, `serde_json`: For serialization/deserialization.
75+
* IPC Crate (e.g., `interprocess`): For listening to HAPPE.
76+
* `@mcp` or MCP client logic: For interacting with the Memory MCP Server.
77+
* (Potentially) Embedding generation crate.
78+
* (Potentially) `@core`: For shared types or utilities.

IDA/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#[tokio::main]
2+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
3+
println!("Starting IDA Daemon...");
4+
5+
// 1. Initialize IPC server/listener for HAPPE
6+
7+
// 2. Initialize MCP client to connect to Memory MCP Server
8+
9+
// 3. Start main loop (listening for IPC requests from HAPPE)
10+
// - On receive query:
11+
// - Call Memory MCP Server to retrieve memories
12+
// - Send memories back to HAPPE via IPC
13+
// - On receive turn info (async):
14+
// - Analyze turn data
15+
// - Decide what to store
16+
// - (Optional: Generate embeddings)
17+
// - Call Memory MCP Server to check for duplicates
18+
// - Call Memory MCP Server to store new memories
19+
20+
println!("IDA Daemon shutting down.");
21+
Ok(())
22+
}

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ The Gemini Rust Suite is a modular project composed of several crates within a C
3131
* Core configuration loading (`GeminiConfig` from TOML) and error handling (`GeminiError`).
3232
* Shared JSON-RPC types (`Request`, `Response`, `ServerCapabilities`, `Tool`) used by MCP.
3333

34+
* **`gemini-ipc`**: Centralizes Inter-Process Communication definitions:
35+
* Defines standardized Rust structs/enums for messages passed between different daemons/clients (e.g., `gemini-cli`, `mcp-hostd`, `HAPPE`, `IDA`).
36+
* Ensures consistent communication protocols (relies on `serde` for serialization).
37+
3438
* **`gemini-mcp`**: Implements the **host** side of the Model Context Protocol (MCP):
3539
* `McpHost` manages discovering, launching (via stdio, SSE, WebSocket), and communicating with MCP **servers** (external tools/services).
3640
* Handles JSON-RPC communication for tool execution (`mcp/tool/execute`) and resource retrieval.
3741
* Translates between Gemini function calling and MCP tool execution.
38-
* Includes the `mcp-hostd` binary, a standalone MCP host daemon.
42+
* Includes the `mcp-hostd` binary, a standalone MCP host daemon (uses `gemini-ipc` for client communication).
3943
* Provides the source for built-in MCP servers (`filesystem`, `command`, `memory_store`).
4044

4145
* **`gemini-memory`**: Implements a persistent, semantic memory store:
@@ -50,9 +54,20 @@ The Gemini Rust Suite is a modular project composed of several crates within a C
5054
* Supports single-shot prompts, interactive chat, and task loops.
5155
* Integrates MCP for tool usage and Memory for context awareness and history.
5256
* Manages user configuration, chat history, and session state.
53-
* Can connect to the `mcp-hostd` daemon or run an embedded `McpHost`.
57+
* Can connect to the `mcp-hostd` daemon (via `gemini-ipc`) or run an embedded `McpHost`.
5458
* Can *also* run the built-in MCP servers directly via flags (`--filesystem-mcp`, etc.).
5559

60+
* **(New) `HAPPE`**: Host Application Environment daemon:
61+
* Intended as the primary execution environment, replacing direct CLI usage for more complex scenarios.
62+
* Manages interactions between users/clients, the main LLM, `IDA`, and MCP servers.
63+
* Uses `gemini-ipc` to communicate with `IDA`.
64+
* Handles LLM calls and LLM-initiated MCP tool execution.
65+
66+
* **(New) `IDA`**: Internal Dialogue App daemon:
67+
* Manages persistent memory and other background cognitive tasks.
68+
* Communicates with `HAPPE` via `gemini-ipc`.
69+
* Interacts with the Memory MCP Server (via `gemini-mcp` client logic) for retrieval and storage.
70+
5671
## 🚀 Features
5772

5873
This suite provides a comprehensive set of features through its components:

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ anyhow = "1.0"
3333
gemini-core = { path = "../core" }
3434
gemini-mcp = { path = "../mcp" }
3535
gemini-memory = { path = "../memory" }
36+
ipc = { path = "../ipc" }
3637

3738
[[bin]]
3839
name = "gemini-cli-bin"

0 commit comments

Comments
 (0)