local-automata 0.1.0__tar.gz

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.
Files changed (42) hide show
  1. local_automata-0.1.0/LICENSE +201 -0
  2. local_automata-0.1.0/PKG-INFO +349 -0
  3. local_automata-0.1.0/README.md +316 -0
  4. local_automata-0.1.0/backend/local_automata/__init__.py +55 -0
  5. local_automata-0.1.0/backend/local_automata/agent.py +340 -0
  6. local_automata-0.1.0/backend/local_automata/cli.py +275 -0
  7. local_automata-0.1.0/backend/local_automata/colors.py +24 -0
  8. local_automata-0.1.0/backend/local_automata/config.py +78 -0
  9. local_automata-0.1.0/backend/local_automata/images.py +89 -0
  10. local_automata-0.1.0/backend/local_automata/llm.py +525 -0
  11. local_automata-0.1.0/backend/local_automata/mcp_client.py +133 -0
  12. local_automata-0.1.0/backend/local_automata/server.py +205 -0
  13. local_automata-0.1.0/backend/local_automata/server_cli.py +126 -0
  14. local_automata-0.1.0/backend/local_automata/settings.py +283 -0
  15. local_automata-0.1.0/backend/local_automata/spinner.py +96 -0
  16. local_automata-0.1.0/backend/local_automata/tools/__init__.py +86 -0
  17. local_automata-0.1.0/backend/local_automata/tools/base.py +41 -0
  18. local_automata-0.1.0/backend/local_automata/tools/filesystem.py +205 -0
  19. local_automata-0.1.0/backend/local_automata/tools/memory.py +79 -0
  20. local_automata-0.1.0/backend/local_automata/tools/plan.py +67 -0
  21. local_automata-0.1.0/backend/local_automata/tools/shell.py +78 -0
  22. local_automata-0.1.0/backend/local_automata/tools/workspace.py +102 -0
  23. local_automata-0.1.0/backend/local_automata/webapp.py +325 -0
  24. local_automata-0.1.0/backend/local_automata.egg-info/PKG-INFO +349 -0
  25. local_automata-0.1.0/backend/local_automata.egg-info/SOURCES.txt +40 -0
  26. local_automata-0.1.0/backend/local_automata.egg-info/dependency_links.txt +1 -0
  27. local_automata-0.1.0/backend/local_automata.egg-info/entry_points.txt +4 -0
  28. local_automata-0.1.0/backend/local_automata.egg-info/requires.txt +16 -0
  29. local_automata-0.1.0/backend/local_automata.egg-info/top_level.txt +1 -0
  30. local_automata-0.1.0/pyproject.toml +70 -0
  31. local_automata-0.1.0/setup.cfg +4 -0
  32. local_automata-0.1.0/tests/test_agent.py +147 -0
  33. local_automata-0.1.0/tests/test_cli.py +89 -0
  34. local_automata-0.1.0/tests/test_colors.py +22 -0
  35. local_automata-0.1.0/tests/test_config.py +50 -0
  36. local_automata-0.1.0/tests/test_images.py +58 -0
  37. local_automata-0.1.0/tests/test_llm.py +124 -0
  38. local_automata-0.1.0/tests/test_mcp.py +97 -0
  39. local_automata-0.1.0/tests/test_server.py +79 -0
  40. local_automata-0.1.0/tests/test_settings.py +82 -0
  41. local_automata-0.1.0/tests/test_tools.py +150 -0
  42. local_automata-0.1.0/tests/test_webapp.py +192 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,349 @@
1
+ Metadata-Version: 2.4
2
+ Name: local-automata
3
+ Version: 0.1.0
4
+ Summary: ローカルLLM(mlx / llama.cpp / OpenAI互換)で動く、ツール・プロファイル対応の汎用エージェントのコア
5
+ Author: ToPo-ToPo-ToPo
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/ToPo-ToPo-ToPo/local-automata
8
+ Keywords: llm,agent,coding-agent,local-llm,mlx,llama.cpp,openai
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Software Development
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: openai>=1.0
20
+ Requires-Dist: mcp>=1.0
21
+ Requires-Dist: pypdf>=4.0
22
+ Requires-Dist: mlx-lm>=0.31.3; sys_platform == "darwin" and platform_machine == "arm64"
23
+ Requires-Dist: mlx-vlm>=0.5.0; sys_platform == "darwin" and platform_machine == "arm64"
24
+ Requires-Dist: twine>=6.2.0
25
+ Provides-Extra: science
26
+ Requires-Dist: matplotlib>=3.10; extra == "science"
27
+ Requires-Dist: numpy>=2.0; extra == "science"
28
+ Requires-Dist: pandas>=2.2; extra == "science"
29
+ Requires-Dist: scikit-learn>=1.5; extra == "science"
30
+ Requires-Dist: scipy>=1.13; extra == "science"
31
+ Requires-Dist: sympy>=1.13; extra == "science"
32
+ Dynamic: license-file
33
+
34
+ # local-automata
35
+
36
+ ローカルLLM(mlx / llama.cpp)で動く、最小の汎用コーディングエージェント。
37
+ LLM とツール(ファイル読み書き・編集・検索・シェル実行)を組み合わせた agent loop が土台で、
38
+ 設定(`agent.toml` + 指示 `AGENTS.md`)だけでコーダー以外のエージェント
39
+ (キャラクターチャット等)にも転用できる。
40
+
41
+ > 挙動の詳細な仕様は [SPEC.md](SPEC.md) を参照。
42
+
43
+ ## 目次
44
+
45
+ - [クイックスタート](#クイックスタート)
46
+ - [使い方](#使い方)
47
+ - [設定(agent.toml)](#設定agenttoml)
48
+ - [ツールと安全性](#ツールと安全性)
49
+ - [機能とオプション](#機能とオプション)
50
+ - [ローカルLLMサーバー](#ローカルllmサーバー)
51
+ - [サンプル](#サンプル)
52
+ - [ライブラリとして使う](#ライブラリとして使う)
53
+ - [構成とテスト](#構成とテスト)
54
+
55
+ ## クイックスタート
56
+
57
+ [uv](https://docs.astral.sh/uv/) を使う。3ステップで動く。
58
+
59
+ ```sh
60
+ # 1. 環境構築(OS を自動判定。Apple Silicon では mlx も入る)
61
+ uv sync
62
+
63
+ # 2. ローカルLLMサーバーを起動(別ターミナルで)
64
+ uv run local-automata-server
65
+
66
+ # 3. エージェントを起動
67
+ uv run local-automata # ターミナルで対話
68
+ uv run local-automata-web # ブラウザのチャット GUI(http://127.0.0.1:8765)
69
+ ```
70
+
71
+ モデル・接続先・ツールなどの挙動はすべて **`agent.toml`(無ければ既定値)** で決まる
72
+ (→ [設定](#設定agenttoml))。`uv run` の代わりに `.venv` を有効化すれば
73
+ `local-automata` を直接呼べる。
74
+
75
+ ## 使い方
76
+
77
+ ### ターミナル(`local-automata`)
78
+
79
+ 対話形式。プロンプトを入力するたびに、エージェントがツールを使ってタスクを進める。
80
+ 会話履歴はセッション内で保持される。
81
+
82
+ ```sh
83
+ uv run local-automata
84
+ # > src/ のテストを実行して落ちている箇所を直して
85
+ # > さっきの修正にテストを追加して
86
+ ```
87
+
88
+ - コマンド: `/help`・`/reset`(履歴クリア)・`/img`/`/file`(添付)・`exit`(終了、Ctrl-D も可)
89
+ - 応答はストリーミング表示(既定)。不具合が出る場合は `agent.toml` で `stream = false`。
90
+ - 履歴が `max_context_chars` を超えると、古いやり取りを自動で要約して圧縮する。
91
+
92
+ **画像・ファイルの添付**(ターミナル):
93
+
94
+ ```
95
+ > /img photo.png この画像を説明して # vision 対応モデル+サーバーが必要。複数はカンマ区切り、URL も可
96
+ > /file paper.pdf この論文の要点をまとめて # PDF はテキスト抽出。CSV/TXT/JSON/MD も可
97
+ ```
98
+
99
+ > 大きなデータは添付せず `workspace/` に置き、pandas 等で処理させる方が文脈を消費せず確実。
100
+
101
+ ### ブラウザ GUI(`local-automata-web`)
102
+
103
+ 追加依存なし(標準ライブラリのみ)の簡易チャット画面。設定は CLI と同じ `agent.toml` から読む。
104
+
105
+ ```sh
106
+ uv run local-automata-web # http://127.0.0.1:8765 を開く
107
+ uv run local-automata-web --port 9000 --no-browser
108
+ ```
109
+
110
+ - 応答を SSE でストリーミング表示し、**生成したコードや画像(グラフ)も画面に表示**する。
111
+ - 生成物はセッションごとの `workspace/<日時>_<タイトル>/` に保存。「+ 新しいチャット」で別フォルダに切替。
112
+ - フロントエンドの静的ファイルはリポジトリ直下の `frontend/` に分離している。
113
+
114
+ ## 設定(agent.toml)
115
+
116
+ モデル・パラメータ・運用設定はすべて **`agent.toml`(+既定値)** で指定する。
117
+ **CLI 引数や環境変数では指定しない**(CLI は設定・プロファイル選択用の `--config` / `--profile` のみ)。
118
+ 設定はトップレベル、または `[profiles.<name>]` 配下に書く。
119
+
120
+ ```toml
121
+ # agent.toml
122
+ model = "mlx-community/Qwen3.6-27B-4bit"
123
+ base_url = "http://localhost:8080/v1"
124
+ backend = "mlx" # mlx / llama-cpp(省略時は OS 自動判定)
125
+ temperature = 0.2
126
+ max_tokens = 16384
127
+ max_steps = 50
128
+ max_context_chars = 24000
129
+ enable_thinking = false
130
+ stream = true
131
+ tool_mode = "native" # native / prompt
132
+ allow_install = false # run_command でのパッケージ導入を許可するか
133
+ auto_start = false # サーバーが無ければ自動起動するか
134
+ parallel = 1 # 自動起動時の同時処理スロット数(llama.cpp)
135
+ workdir = "workspace" # ツールの作業ディレクトリ('.' で現ディレクトリ)
136
+ planning = false # 着手前に計画を立てさせるか
137
+ ```
138
+
139
+ | キー | 既定 | 説明 |
140
+ | --- | --- | --- |
141
+ | `model` | `mlx-community/Qwen3.6-27B-4bit` | モデル名/パス |
142
+ | `base_url` | `http://localhost:8080/v1` | OpenAI 互換エンドポイント |
143
+ | `backend` | OS自動(macOS arm64→`mlx`、他→`llama-cpp`) | 自動起動するバックエンド |
144
+ | `temperature` | `0.2` | サンプリング温度 |
145
+ | `max_tokens` | `16384` | 1応答の最大生成トークン |
146
+ | `max_steps` | `50` | 1タスクの最大ツール往復回数 |
147
+ | `max_context_chars` | `24000` | 超えると古い履歴を要約して圧縮 |
148
+ | `enable_thinking` | `false` | 思考(thinking)モード |
149
+ | `stream` | `true` | ストリーミング表示 |
150
+ | `request_timeout` | (無制限) | LLM 応答の読み取りタイムアウト秒数(0/未指定で無制限) |
151
+ | `tool_mode` | `native` | ツール呼び出し方式 `native` / `prompt` |
152
+ | `allow_install` | `false` | `run_command` でのパッケージ導入許可 |
153
+ | `auto_start` | `false` | サーバー自動起動(既定は接続専用) |
154
+ | `parallel` | (なし) | 自動起動時の並列スロット数(llama.cpp) |
155
+ | `workdir` | `workspace` | ツールの作業ディレクトリ |
156
+ | `planning` | `false` | 着手前の計画 |
157
+ | `debug` | `false` | LLM 呼び出しの所要時間・サイズや各ステップを stderr に出す |
158
+
159
+ **指示(システムプロンプト)は Markdown** で分けて書く(Codex / Claude Code と同様)。
160
+ 既定で `./AGENTS.md` を読み込み、`instructions_file` でパス変更、無ければ組み込み既定を使う。
161
+ サンプルは `AGENTS.md.example` / `agent.toml.example`。
162
+
163
+ ```markdown
164
+ <!-- AGENTS.md -->
165
+ あなたは読み取り専用アシスタントです。まずファイルを読んでから判断してください。
166
+ ```
167
+
168
+ ## ツールと安全性
169
+
170
+ 利用可能なツール: `read_file` / `write_file` / `edit_file` / `list_dir` / `grep` / `glob` / `run_command`。
171
+ `agent.toml` の `tools` で絞り込める(省略=全部、`[]`=無し)。
172
+
173
+ **作業ディレクトリ**:
174
+
175
+ - 既定で `./workspace`(自動作成)に閉じ込められる。`workdir = "."` で現ディレクトリ(既存プロジェクト編集用)。
176
+ - 各実行は `workspace/<日時>_<タイトル>/` に分離保存され、検討ごとに混ざらない(タイトルは最初のタスクから LLM が生成)。
177
+ - ファイルツールは workspace の外を拒否(`..`・絶対パス・シンボリックリンクをブロック)。
178
+ - `run_command` は workspace を作業ディレクトリとして実行する。ただしシェルは絶対パスや `cd` で外へ出られるため、
179
+ これは隔離ではない。**信頼できないモデル/タスクはコンテナ/VM(できればネットワーク制限付き)で実行する**こと。
180
+ - パッケージ導入は既定でブロック(`pip/uv/conda/npm/apt …` を検出して拒否)。許可は `allow_install = true`。
181
+ 導入する場合は `uv pip install`、恒久的に必要なら `pyproject.toml` に追加して `uv sync`。
182
+
183
+ ## 機能とオプション
184
+
185
+ ### ツール呼び出し方式(`tool_mode`)
186
+
187
+ - **native(既定)**: OpenAI の function calling。形式は正確だが、mlx ではツール呼び出しが一括生成のため
188
+ コード部分はストリーミングされない。
189
+ - **prompt**: ツール仕様をプロンプトに注入し、応答中の `tool` コードブロック(JSON)を解析。
190
+ **コード生成もストリーミングされ**、ツール非対応モデルでも動く。形式はモデルの指示追従に依存。
191
+
192
+ ### 思考(thinking)モード
193
+
194
+ `enable_thinking`(既定 false)。サーバー側は `local-automata-server --thinking` / `--no-thinking` で切替。
195
+ mlx_lm.server は起動時に固定(リクエスト単位の上書き不可)、vLLM 等はリクエスト単位で反映。
196
+ MLX 変換モデルの一部はテンプレートが未対応で効かないことがある。
197
+
198
+ ### 計画モード・固定ワークフロー
199
+
200
+ - `planning = true` … 着手前にタスクを分解する `update_plan`(チェックリスト)ツールを追加し、
201
+ 「計画 → 実行 → 検証」の手順を促す。多段タスクの成功率が上がりやすい。
202
+ - `workflow_file = "workflow.md"` … 決まった手順を外部 Markdown で渡して従わせる(`update_plan` と併用可)。
203
+
204
+ ### 長期メモリ
205
+
206
+ `[memory] enabled = true` で、セッションをまたいで記憶する `remember` / `recall` ツールが有効になる。
207
+ `path` をプロファイルごとに分ければキャラクター単位の記憶になる。
208
+
209
+ ```toml
210
+ [memory]
211
+ enabled = true
212
+ path = ".coder/memory.json"
213
+ ```
214
+
215
+ ### MCP サーバー
216
+
217
+ `[mcp.servers.<name>]` に `command`(ローカルプロセス)か `url`(リモート)を書くと、
218
+ その MCP サーバーのツールが起動時に自動で取り込まれ、`<name>_<ツール名>` で使える(追加インストール不要)。
219
+
220
+ ```toml
221
+ [mcp.servers.fs]
222
+ command = "npx"
223
+ args = ["-y", "@modelcontextprotocol/server-filesystem", "/data"]
224
+
225
+ [mcp.servers.remote]
226
+ url = "http://localhost:3000/sse"
227
+ ```
228
+
229
+ ### プロファイル
230
+
231
+ 用途ごとに「指示(Markdown)+ツール+モデル・パラメータ」を1セットとして `[profiles.<name>]` に定義し、
232
+ `--profile <name>` または `default_profile` で切り替える。
233
+
234
+ ```toml
235
+ default_profile = "coder"
236
+
237
+ [profiles.coder]
238
+ instructions_file = "AGENTS.md"
239
+ tools = ["read_file", "write_file", "edit_file", "list_dir", "run_command"]
240
+
241
+ [profiles.luna] # キャラクターチャットの例
242
+ instructions_file = "characters/luna.md"
243
+ tools = [] # ツールを使わない純粋な会話
244
+ ```
245
+
246
+ ```sh
247
+ uv run local-automata --profile luna
248
+ ```
249
+
250
+ ## ローカルLLMサーバー
251
+
252
+ `local-automata-server` が mlx / llama.cpp を OpenAI 互換 API で起動する(応答可能になるまで待つ)。
253
+ `--backend` の既定は OS 自動判定(macOS Apple Silicon → `mlx`、他 → `llama-cpp`)。
254
+
255
+ ```sh
256
+ uv run local-automata-server # 既定(OSに応じたバックエンド+既定モデル)
257
+ uv run local-automata-server --backend llama-cpp --model /path/to/model.gguf
258
+ uv run local-automata-server --model model.gguf -- --ctx-size 8192 --jinja # -- 以降はバックエンド固有引数
259
+ ```
260
+
261
+ - `--host` / `--port`(既定 `127.0.0.1:8080`)、`--thinking` / `--no-thinking`。
262
+ - **並列処理**: llama.cpp は `--parallel N`(continuous batching。スロット数だけ KV キャッシュを消費)。
263
+ mlx は逐次処理なので `--instances N` で連番ポートに N 個起動する(重みは N 倍のメモリ)。
264
+
265
+ ### 接続のしかた
266
+
267
+ `local-automata` は起動時に `base_url` のサーバーが応答するか判定する。
268
+
269
+ - **既定(接続専用)**: 既存サーバーに相乗りする(停止しない)。無ければ起動方法を案内して終了。
270
+ - **`auto_start = true`**: サーバーが無ければ自動起動し、終了時に停止する。
271
+
272
+ **複数エージェントの同時実行**: 共有サーバーを1台だけ起動し(llama.cpp は `--parallel` をエージェント数以上に)、
273
+ 各ターミナルで別プロファイルを接続する。接続専用が既定なので相乗りが安全。
274
+
275
+ ```sh
276
+ uv run local-automata-server --backend llama-cpp --model model.gguf --parallel 2
277
+ uv run local-automata --profile analyzer # ターミナル1
278
+ uv run local-automata --profile luna # ターミナル2
279
+ ```
280
+
281
+ ## サンプル
282
+
283
+ `examples/` に用途別のエージェント一式がある。サーバーを起動した上で、各ディレクトリで実行する。
284
+
285
+ | ディレクトリ | 内容 |
286
+ | --- | --- |
287
+ | `examples/character/` | 会話のみ(ツールなし)+長期メモリの「ルナ」 |
288
+ | `examples/coder/` | 力学(放物運動など)の数値計算コードを作成 → 実行 → 検証 |
289
+ | `examples/optimizer/` | 作成 → 実行 → 評価 → やり直しを固定ワークフローで反復 |
290
+ | `examples/ml/` | CSV から前処理 → 学習 → 評価 → 保存 |
291
+
292
+ ```sh
293
+ cd examples/coder
294
+ uv run local-automata # CLI(agent.toml を自動読込。生成物は ./workspace/)
295
+ uv run local-automata-web # 同じ設定をブラウザ GUI で
296
+ uv run python run_physics.py # ライブラリとして埋め込む例
297
+ ```
298
+
299
+ 詳細は各ディレクトリの `README.md` を参照。
300
+
301
+ ## ライブラリとして使う
302
+
303
+ PyPI から `uv` でインストールして組み込める(自分のプロジェクトの依存に追加する)。
304
+
305
+ ```sh
306
+ uv add local-automata # コア(mac は mlx、PDF 抽出の pypdf も自動で入る)
307
+ uv add 'local-automata[science]' # 科学計算の例も動かす(numpy/scipy/pandas/...)
308
+ ```
309
+
310
+ ```python
311
+ from local_automata import Agent, Config, LLMClient, build_registry
312
+
313
+ config = Config.load() # 既定。agent.toml の設定を使うなら Config.load(load_agent_config(...).runtime)
314
+ agent = Agent(LLMClient(config), build_registry(), config) # 既定で workspace/ を作る
315
+ print(agent.run("..."))
316
+ ```
317
+
318
+ 設定ファイル(`AGENTS.md` / `agent.toml`)から組み立てるなら `load_agent_config` を使う(`examples/` 参照)。
319
+ 公開 API は `local_automata.__all__` を参照。
320
+
321
+ > mlx は環境マーカーで判定され、**Apple Silicon のときだけ自動で入る**(`uv add local-automata`・
322
+ > `uv sync` 共通。他OSでは自動スキップ)。非mac は llama.cpp(`llama-server` バイナリ)を別途用意する。
323
+ > 開発環境(`uv sync`)はさらに科学計算ライブラリと pytest が全OSで入る。Python は `.python-version`(3.11)。
324
+
325
+ ## 構成とテスト
326
+
327
+ ```
328
+ AGENTS.md.example システムプロンプト(指示 Markdown)のサンプル
329
+ agent.toml.example 設定(TOML)のサンプル
330
+ frontend/ Web GUI の静的ファイル(index.html / style.css / app.js)
331
+ backend/local_automata/ Python パッケージ本体(PyPI に公開される。frontend は含まれない)
332
+ config.py 実行時設定(agent.toml + 既定値)
333
+ settings.py 指示 Markdown と設定 TOML の読み込み
334
+ images.py 画像・文書入力(パス/URL → content パーツ)
335
+ llm.py OpenAI 互換クライアント
336
+ agent.py エージェントループ(ツール呼び出し)
337
+ cli.py CLI / 対話モード(local-automata)
338
+ webapp.py Web GUI サーバー(local-automata-web)
339
+ mcp_client.py MCP サーバー連携(ツール自動取り込み)
340
+ server.py ローカルLLMサーバーのランチャー
341
+ server_cli.py サーバー起動 CLI(local-automata-server)
342
+ spinner.py 進捗表示(生成中/実行中)
343
+ tools/ ツール群(filesystem / shell / memory / plan / workspace)
344
+ tests/ pytest テスト一式
345
+ ```
346
+
347
+ ```sh
348
+ uv run pytest
349
+ ```