docs: expand usage instructions with detailed steps

This commit is contained in:
root
2026-04-15 16:15:35 +08:00
parent 931617624e
commit e8c275c8f8
2 changed files with 216 additions and 22 deletions

View File

@ -49,34 +49,131 @@ ts/
## Usage in WaterFlow
### Method 1: Import as standalone module
This module supports two usage methods: **import as module** or **use as Skill**.
Copy the `ts/` directory to your WaterFlow project:
### Method 1: Import as Module (for developer integration)
#### Step 1: Copy source files
Copy the `ts/` directory to your WaterFlow project, for example:
```
your-waterflow-project/
├── src/
│ └── runtime/
│ └── core/
│ └── graph_memory/ # Copy from ts/src/runtime/core/
└── ts/ # Or place in project root
└── bundled-skills/ # Skill files
```
#### Step 2: Build TypeScript
```bash
cd ts/
npm install
npm run build
```
Compiled files will be output to `ts/dist/`.
#### Step 3: Import in your code
```typescript
import { GraphMemoryTool, createGraphMemoryTool } from './runtime/core/tools/builtin/graph_memory_tool';
import { createGraphMemoryTool } from './runtime/core/tools/builtin/graph_memory_tool';
const tool = createGraphMemoryTool();
const result = await tool.handler({
// Create tool instance, can pass sessionId to distinguish different sessions
const tool = createGraphMemoryTool('my-session-id');
// Prepare execution context
const context = {
toolCallId: 'call-123',
workingDirectory: '/project',
abortController: { signal: {} },
config: { timeout: 30000 },
logger: {
info: console.log,
warn: console.warn,
error: console.error,
debug: console.debug
}
};
// Commit memory example
const commitResult = await tool.handler({
action: 'commit',
params: {
triplets: [
{ subject: 'User', relation: 'likes', object: 'Programming' }
{ subject: 'User', relation: 'likes', object: 'Programming' },
{ subject: 'User', relation: 'is learning', object: 'TypeScript' }
]
}
}, context);
console.log(commitResult);
// Output: {"success":true,"data":{"createdEntities":4,"createdRelations":2}}
// Recall memory example
const recallResult = await tool.handler({
action: 'recall',
params: {
queryIntent: 'User Programming'
}
}, context);
console.log(recallResult);
// Output: {"success":true,"data":{"entities":[...],"relations":[...],"message":"Found X entities, Y relations"}}
```
### Method 2: Use Skill
### Method 2: Use Skill (recommended for AI Agent)
GraphMemory is configured as a bundled skill and can be called directly:
#### Step 1: Configure Skill source
In your WaterFlow project, find the Skill configuration file and add bundled source pointing to this project's Skill directory:
```typescript
// skill_interface.ts or config file
import { DEFAULT_SKILL_LOADER_CONFIG } from './skill_interface';
const config = {
...DEFAULT_SKILL_LOADER_CONFIG,
sources: {
...DEFAULT_SKILL_LOADER_CONFIG.sources,
bundled: './ts/bundled-skills' // Point to this project's Skill directory
},
enabledSources: ['project', 'bundled']
};
```
#### Step 2: Call Skill via Agent
In your Agent or Workflow, call Skill via Tool:
```
Use skill:graph_memory for memory operations
Use skill:graph_memory_persona for persona management
Use skill:graph_memory_task for task management
Use skill:graph_memory for:
1. Commit memory: I like programming, learning TypeScript
2. Recall memory: Find memories related to me and programming
```
Or call via code:
```typescript
// Call via SkillTool
const skillResult = await skillTool.handler({
skill: 'graph_memory',
args: 'recall - queryIntent: "User learning"'
}, context);
```
#### Available Skills
| Skill Name | Function | Use Case |
|------------|----------|----------|
| `graph_memory` | Memory CRUD | Read/Write/Delete memories |
| `graph_memory_persona` | Persona management | Set AI role/personality |
| `graph_memory_task` | Task management | Create/update long-term tasks |
---
## API