@aigne/example-afs-local-fs 1.1.0-beta

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.
@@ -0,0 +1,44 @@
1
+ # Change the name of this file to .env.local and fill in the following values
2
+
3
+ # Uncomment the lines below to enable debug logging
4
+ # DEBUG="aigne:*"
5
+
6
+ # Use different Models
7
+
8
+ # OpenAI
9
+ # MODEL="openai/gpt-4.1"
10
+ # OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
11
+
12
+ # Anthropic claude
13
+ # MODEL="anthropic/claude-3-7-sonnet-latest"
14
+ # ANTHROPIC_API_KEY=""
15
+
16
+ # Gemini
17
+ MODEL="google/gemini-2.5-pro"
18
+ # GEMINI_API_KEY=""
19
+
20
+ # Bedrock nova
21
+ # MODEL=bedrock:us.amazon.nova-premier-v1:0
22
+ # AWS_ACCESS_KEY_ID=""
23
+ # AWS_SECRET_ACCESS_KEY=""
24
+ # AWS_REGION=us-west-2
25
+
26
+ # DeepSeek
27
+ # MODEL="deepseek/deepseek-chat"
28
+ # DEEPSEEK_API_KEY=""
29
+
30
+ # OpenRouter
31
+ # MODEL="openrouter/openai/gpt-4o"
32
+ # OPEN_ROUTER_API_KEY=""
33
+
34
+ # xAI
35
+ # MODEL="xai/grok-2-latest"
36
+ # XAI_API_KEY=""
37
+
38
+ # Ollama
39
+ # MODEL="ollama/llama3.2"
40
+ # OLLAMA_DEFAULT_BASE_URL="http://localhost:11434/v1";
41
+
42
+
43
+ # Setup proxy if needed
44
+ # HTTPS_PROXY=http://localhost:7890
package/LICENSE.md ADDED
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ *As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of
71
+ legal claim.*
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the entity offering these terms, and the **software** is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ **you** refers to the individual or entity agreeing to these terms.
80
+
81
+ **your company** is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that
84
+ organization. **control** means ownership of substantially all the assets of an
85
+ entity, or the power to direct its management and policies by vote, contract, or
86
+ otherwise. Control can be direct or indirect.
87
+
88
+ **your licenses** are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ **use** means anything you do with the software requiring one of your licenses.
92
+
93
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,259 @@
1
+ # AFS LocalFS Example
2
+
3
+ <p align="center">
4
+ <picture>
5
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo-dark.svg" media="(prefers-color-scheme: dark)">
6
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" media="(prefers-color-scheme: light)">
7
+ <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" alt="AIGNE Logo" width="400" />
8
+ </picture>
9
+ </p>
10
+
11
+ This example shows how to mount your local file system as an AFS module, enabling AI agents to intelligently search, read, and interact with your files. We demonstrate mounting the AIGNE framework documentation.
12
+
13
+ ## What You'll See
14
+
15
+ **User asks:** "What is AIGNE?"
16
+
17
+ **Behind the scenes:**
18
+ 1. LLM calls `afs_search` → searches all files for "AIGNE"
19
+ 2. Finds `/modules/local-fs/docs/getting-started/what-is-aigne.md`
20
+ 3. LLM calls `afs_read` → reads the specific file
21
+ 4. LLM presents: "AIGNE is a framework and runtime engine for building LLM-powered applications..."
22
+
23
+ **The power:** AI agents intelligently search your file system and retrieve exactly what's needed - no manual navigation required!
24
+
25
+ ## Prerequisites
26
+
27
+ * [Node.js](https://nodejs.org) (>=20.0) and npm installed on your machine
28
+ * An [OpenAI API key](https://platform.openai.com/api-keys) for interacting with OpenAI's services
29
+ * Optional dependencies (if running the example from source code):
30
+ * [Pnpm](https://pnpm.io) for package management
31
+ * [Bun](https://bun.sh) for running unit tests & examples
32
+
33
+ ## Quick Start (No Installation Required)
34
+
35
+ ```bash
36
+ export OPENAI_API_KEY=YOUR_OPENAI_API_KEY
37
+
38
+ # Mount AIGNE framework docs (clone first)
39
+ git clone https://github.com/AIGNE-io/aigne-framework
40
+ npx -y @aigne/example-afs-local-fs --path ./aigne-framework --chat
41
+
42
+ # Or mount any directory
43
+ npx -y @aigne/example-afs-local-fs --path ~/Documents --description "My Documents" --chat
44
+
45
+ # Ask a specific question
46
+ npx -y @aigne/example-afs-local-fs --path . --input "What is AIGNE?"
47
+ ```
48
+
49
+ ## See It In Action
50
+
51
+ Here's what happens when you ask "What is AIGNE?" with the framework docs mounted:
52
+
53
+ ```
54
+ 👤 You: "What is AIGNE?"
55
+
56
+ 🤖 Agent thinks: I should search the docs for information about AIGNE...
57
+ → Calls: afs_search(query: "AIGNE")
58
+
59
+ 📁 Found 15 matching files:
60
+ • docs/getting-started/what-is-aigne.md ⭐ (most relevant)
61
+ • README.md
62
+ • docs/core-concepts/overview.md
63
+ ...
64
+
65
+ 🤖 Agent thinks: Let me read the most relevant file...
66
+ → Calls: afs_read("docs/getting-started/what-is-aigne.md")
67
+
68
+ 📄 File loaded (2.4 KB)
69
+
70
+ 🤖 AI: "AIGNE is a framework and runtime engine for building LLM-powered
71
+ applications and AI agents. It provides:
72
+
73
+ • A unified Agentic File System (AFS) interface
74
+ • Support for multiple LLM providers (OpenAI, Anthropic, etc.)
75
+ • Tools for building autonomous agents
76
+ • Integration with external services via MCP
77
+
78
+ Would you like me to walk you through a quick-start tutorial, or
79
+ would you prefer to see specific examples?"
80
+ ```
81
+
82
+ **Key insight:** The agent intelligently searches, finds the right file, reads it, and synthesizes a helpful answer - all automatically!
83
+
84
+ ## Installation
85
+
86
+ ### Clone the Repository
87
+
88
+ ```bash
89
+ git clone https://github.com/AIGNE-io/aigne-framework
90
+ ```
91
+
92
+ ### Install Dependencies
93
+
94
+ ```bash
95
+ cd aigne-framework/examples/afs-local-fs
96
+
97
+ pnpm install
98
+ ```
99
+
100
+ ### Setup Environment Variables
101
+
102
+ Setup your OpenAI API key in the `.env.local` file:
103
+
104
+ ```bash
105
+ OPENAI_API_KEY="" # Set your OpenAI API key here
106
+ ```
107
+
108
+ #### Using Different Models
109
+
110
+ You can use different AI models by setting the `MODEL` environment variable along with the corresponding API key. The framework supports multiple providers:
111
+
112
+ * **OpenAI**: `MODEL="openai:gpt-4.1"` with `OPENAI_API_KEY`
113
+ * **Anthropic**: `MODEL="anthropic:claude-3-7-sonnet-latest"` with `ANTHROPIC_API_KEY`
114
+ * **Google Gemini**: `MODEL="gemini:gemini-2.0-flash"` with `GEMINI_API_KEY`
115
+ * **AWS Bedrock**: `MODEL="bedrock:us.amazon.nova-premier-v1:0"` with AWS credentials
116
+ * **DeepSeek**: `MODEL="deepseek:deepseek-chat"` with `DEEPSEEK_API_KEY`
117
+ * **OpenRouter**: `MODEL="openrouter:openai/gpt-4o"` with `OPEN_ROUTER_API_KEY`
118
+ * **xAI**: `MODEL="xai:grok-2-latest"` with `XAI_API_KEY`
119
+ * **Ollama**: `MODEL="ollama:llama3.2"` with `OLLAMA_DEFAULT_BASE_URL`
120
+
121
+ For detailed configuration examples, please refer to the `.env.local.example` file in this directory.
122
+
123
+ ### Run the Example
124
+
125
+ ```bash
126
+ # Run with your current directory
127
+ pnpm start --path .
128
+
129
+ # Run with a specific directory
130
+ pnpm start --path ~/Documents --description "My Documents"
131
+
132
+ # Run in interactive chat mode
133
+ pnpm start --path . --chat
134
+ ```
135
+
136
+ ## How It Works: 3 Simple Steps
137
+
138
+ ### 1. Create LocalFS Module
139
+
140
+ ```typescript
141
+ import { LocalFS } from "@aigne/afs-local-fs";
142
+
143
+ const localFS = new LocalFS({
144
+ localPath: './aigne-framework',
145
+ description: 'AIGNE framework documentation'
146
+ });
147
+ ```
148
+
149
+ ### 2. Mount It as an AFS Module
150
+
151
+ ```typescript
152
+ import { AFS } from "@aigne/afs";
153
+ import { AFSHistory } from "@aigne/afs-history";
154
+
155
+ const afs = new AFS()
156
+ .mount(new AFSHistory({ storage: { url: ":memory:" } }))
157
+ .mount(localFS); // Mounted at /modules/local-fs
158
+ ```
159
+
160
+ ### 3. Create an AI Agent
161
+
162
+ ```typescript
163
+ import { AIAgent } from "@aigne/core";
164
+
165
+ const agent = AIAgent.from({
166
+ instructions: "Help users find and read files from the local file system.",
167
+ inputKey: "message",
168
+ afs, // Agent gets: afs_list, afs_read, afs_write, afs_search
169
+ });
170
+ ```
171
+
172
+ **That's it!** The agent can now intelligently search and retrieve files from your local directory.
173
+
174
+ ### What the Agent Can Do
175
+
176
+ - **`afs_list`** - List files and directories (with recursive depth control)
177
+ - **`afs_read`** - Read file contents and metadata
178
+ - **`afs_write`** - Create or update files
179
+ - **`afs_search`** - Fast full-text search using ripgrep (supports regex)
180
+
181
+ All operations are sandboxed to the mounted directory for safety.
182
+
183
+ ## Try These Examples
184
+
185
+ ```bash
186
+ # Mount AIGNE docs and ask questions
187
+ git clone https://github.com/AIGNE-io/aigne-framework
188
+ npx -y @aigne/example-afs-local-fs --path ./aigne-framework --input "What is AIGNE?"
189
+
190
+ # Ask about specific features
191
+ npx -y @aigne/example-afs-local-fs --path ./aigne-framework --input "How does AFS work?"
192
+
193
+ # Search your codebase
194
+ npx -y @aigne/example-afs-local-fs --path . --input "Find all TypeScript files with TODO comments"
195
+
196
+ # Interactive mode - ask follow-up questions
197
+ npx -y @aigne/example-afs-local-fs --path ~/Documents --chat
198
+ ```
199
+
200
+ **In chat mode, try:**
201
+ - "What files are in this directory?"
202
+ - "Show me the README"
203
+ - "Search for 'authentication' in all files"
204
+ - "Find all Python files"
205
+ - "What does the config.json file contain?"
206
+
207
+ ## Use Cases
208
+
209
+ ### Documentation Chat
210
+ Mount your project docs and let users ask questions:
211
+ ```typescript
212
+ const afs = new AFS()
213
+ .mount(new LocalFS({ localPath: './docs', description: 'Project documentation' }));
214
+ // Users can now ask: "How do I configure authentication?"
215
+ ```
216
+
217
+ ### Codebase Analysis
218
+ Give AI agents access to your codebase:
219
+ ```typescript
220
+ const afs = new AFS()
221
+ .mount(new LocalFS({ localPath: './src', description: 'Source code' }));
222
+ // Agent can search, read, and explain code
223
+ ```
224
+
225
+ ### File Organization
226
+ Let AI help organize your files:
227
+ ```typescript
228
+ const afs = new AFS()
229
+ .mount(new LocalFS({ localPath: '~/Downloads', description: 'Downloads folder' }));
230
+ // Ask: "Find all PDFs from last week" or "Organize these files by type"
231
+ ```
232
+
233
+ ### Multi-Directory Access
234
+ Mount multiple directories simultaneously:
235
+ ```typescript
236
+ const afs = new AFS()
237
+ .mount("/docs", new LocalFS({ localPath: './docs' }))
238
+ .mount("/src", new LocalFS({ localPath: './src' }))
239
+ .mount("/tests", new LocalFS({ localPath: './tests' }));
240
+ // Agent can search across all mounted directories
241
+ ```
242
+
243
+ ## Related Examples
244
+
245
+ - [AFS Memory Example](../afs-memory/README.md) - Conversational memory with user profiles
246
+ - [AFS MCP Server Example](../afs-mcp-server/README.md) - Integration with MCP servers
247
+
248
+ ## Related Packages
249
+
250
+ - [@aigne/afs](../../afs/README.md) - AFS core package
251
+ - [@aigne/afs-local-fs](../../afs/local-fs/README.md) - LocalFS module documentation
252
+
253
+ ## TypeScript Support
254
+
255
+ This package includes full TypeScript type definitions.
256
+
257
+ ## License
258
+
259
+ [MIT](../../LICENSE.md)
package/index.test.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { expect, test } from "bun:test";
2
+ import { runExampleTest } from "@aigne/test-utils/run-example-test.js";
3
+
4
+ test(
5
+ "should successfully run the chatbot",
6
+ async () => {
7
+ const { status } = await runExampleTest();
8
+ expect(status).toBe(0);
9
+ },
10
+ { timeout: 600000 },
11
+ );
package/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env npx -y bun
2
+
3
+ import { AFS } from "@aigne/afs";
4
+ import { AFSHistory } from "@aigne/afs-history";
5
+ import { LocalFS } from "@aigne/afs-local-fs";
6
+ import { loadAIGNEWithCmdOptions, runWithAIGNE } from "@aigne/cli/utils/run-with-aigne.js";
7
+ import { AIAgent } from "@aigne/core";
8
+ import yargs from "yargs";
9
+
10
+ const argv = yargs()
11
+ .option("path", {
12
+ type: "string",
13
+ describe: "Path to the directory to mount",
14
+ default: ".",
15
+ })
16
+ .option("description", {
17
+ type: "string",
18
+ default: "Working directory mounted from local file system",
19
+ describe: "Description of the mounted file system",
20
+ })
21
+ .demandOption("path")
22
+ .strict(false)
23
+ .parseSync(process.argv);
24
+
25
+ const aigne = await loadAIGNEWithCmdOptions();
26
+
27
+ const afs = new AFS()
28
+ .mount(new AFSHistory({ storage: { url: ":memory:" } })) // In-memory history for this example
29
+ .mount(new LocalFS({ localPath: argv.path, description: argv.description }));
30
+
31
+ const agent = AIAgent.from({
32
+ instructions:
33
+ "You are a friendly chatbot that can retrieve files from a virtual file system. You should use the provided functions to list, search, and read files as needed to answer user questions.",
34
+ inputKey: "message",
35
+ afs,
36
+ });
37
+
38
+ await runWithAIGNE(agent, {
39
+ aigne,
40
+ chatLoopOptions: {
41
+ welcome:
42
+ "Hello! I'm a chatbot that can help you interact with a local file system mounted on AFS. Ask me anything about the files!",
43
+ },
44
+ });
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@aigne/example-afs-local-fs",
3
+ "version": "1.1.0-beta",
4
+ "description": "A demonstration of using AIGNE Framework with AFS LocalFS module",
5
+ "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
6
+ "homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/afs-local-fs",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/AIGNE-io/aigne-framework"
11
+ },
12
+ "bin": "index.ts",
13
+ "files": [
14
+ ".env.local.example",
15
+ "*.ts",
16
+ "README.md"
17
+ ],
18
+ "dependencies": {
19
+ "yargs": "^18.0.0",
20
+ "@aigne/afs": "^1.2.0-beta",
21
+ "@aigne/afs-history": "^1.0.0",
22
+ "@aigne/afs-local-fs": "^1.1.0-beta",
23
+ "@aigne/cli": "^1.55.0-beta",
24
+ "@aigne/core": "^1.68.0-beta"
25
+ },
26
+ "devDependencies": {
27
+ "@types/bun": "^1.2.22",
28
+ "@aigne/test-utils": "^0.5.60-beta"
29
+ },
30
+ "scripts": {
31
+ "start": "bun run index.ts",
32
+ "lint": "tsc --noEmit",
33
+ "test:llm": "bun test index.test.ts"
34
+ }
35
+ }