new features
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# Agents in AI Studio
|
||||
|
||||
Agents are reusable roles with separate instructions. In an agent run, AI Studio sends the task and the preceding agents’ work to each role in turn. The reviewer delivers the final response in the chat. Every role uses the model routing already selected for the chat, so you can run a team with one model.
|
||||
|
||||
## Run your first task
|
||||
|
||||
1. Open **Settings → Models** and choose your model and backend. For Ollama, refresh the server's installed models and select a tag. For MLX, select a local model folder or use **Load Model** in **Settings → Model Library**.
|
||||
2. Open **Settings → Agents**. Leave **Planner** and **Specialist** enabled for a first run.
|
||||
3. In the chat composer, turn on **Agents** and enter a task with a clear deliverable. For example, attach two design proposals and ask, “Compare both proposals against the requirements, cite the relevant sections, and draft a recommendation.”
|
||||
4. Send the message. The composer shows the current role. **Settings → Agents → Latest Run** lists the completed stages and the backend each stage reports.
|
||||
5. Read the reviewer's response in the chat. Use **Stop** to cancel an in-progress run. If the reviewer has already started streaming, the chat can retain the interrupted response.
|
||||
|
||||
Turn off **Agents** in the composer to send a regular chat message. The toggle and enabled roles are remembered across launches.
|
||||
|
||||
## Create a custom agent
|
||||
|
||||
1. Open **Settings → Agents → Custom Agents → New Agent**.
|
||||
2. Give the profile a descriptive name, up to 60 characters.
|
||||
3. Write the role instructions, up to 4,000 characters. Describe the task it owns, what evidence to use, and what the next agent should receive.
|
||||
4. Choose **Save Agent** and leave its toggle enabled.
|
||||
5. Turn on **Agents** in chat and send a task that gives the role something concrete to do.
|
||||
|
||||
AI Studio supports up to five saved custom profiles. Enabled profiles run in the order shown, after the optional built-in roles and before the reviewer. Use **Edit** to revise a role, its toggle to temporarily skip it, and **Remove** to delete it. Changes apply to future sends. The same profile can be reused across conversations.
|
||||
|
||||
Here is a profile you can enter in the editor.
|
||||
|
||||
**Name**
|
||||
Technical Editor
|
||||
|
||||
**Instructions**
|
||||
Compare the draft to the user's source material. Preserve public API names and code examples unless the prompt asks to change them. Check terminology for consistency. Hand off an edited draft and a short list of factual claims the reviewer should double-check. Flag any claim for which the source material is missing.
|
||||
|
||||
Other roles can use the same pattern. A **Requirements Analyst** might turn reference material into acceptance criteria. An **Evidence Checker** might review a draft against attached documents and list unsupported claims. A **Release Note Editor** might write a user-facing summary from notes you provide and mark missing version or date information.
|
||||
|
||||
### Built-in roles
|
||||
|
||||
| Role | Work |
|
||||
| --- | --- |
|
||||
| Planner | Breaks down the request and identifies constraints, evidence, and an approach. |
|
||||
| Specialist | Develops the draft and flags gaps. It can request a connected MCP tool when enabled. |
|
||||
| Reviewer | Checks the handoffs against the request and writes the final reply. |
|
||||
|
||||
For a shorter run, disable the planner or specialist, or enable only the custom profiles the task needs. The reviewer always runs when Agents is on. All three built-in profiles have an **Edit** button for their name and instructions. **Restore Default** resets the built-in profile. The specialist keeps its MCP approval role when renamed, and the reviewer still delivers the final reply.
|
||||
|
||||
## Give a run evidence and tools
|
||||
|
||||
Attach documents or select reference material using the regular chat controls. The stages receive the chat context and any enabled recall, excerpts, or tool attachments prepared for the request. If the run uses a remote inference server, that context and the intermediate handoffs are sent to that server.
|
||||
|
||||
For a supervised tool request in the main chat:
|
||||
|
||||
1. Connect the MCP server in **Toolbox** and check that the expected tool is listed.
|
||||
2. In **Settings → Agents**, enable the specialist and **Let the specialist request an MCP tool**.
|
||||
3. Start an agent run and describe the information you need, such as “Search the connected knowledge index for our Laravel authorization guidelines and summarize the relevant sources.”
|
||||
4. If the specialist requests a tool, inspect the server, tool name, and complete JSON arguments. Use **Allow Once** to execute that exact request or **Decline** to continue without it.
|
||||
5. The specialist gets the result or the denial, updates its draft, and passes that draft to subsequent roles.
|
||||
|
||||
The specialist may request one MCP call in each main-chat run. An approval applies to one invocation. Custom roles contribute reasoning and drafts. The side-by-side comparison composer supports agent reasoning and handoffs. For tool results there, run the tool in Toolbox and use its output as reference material. See [MCP setup](MCP.md) for connection details.
|
||||
|
||||
## Models, state, and run limits
|
||||
|
||||
- Each role makes one generation request, with one additional specialist request when it processes a tool outcome. Requests run sequentially within an agent run. More roles mean more latency and context. A small model or context window may work best with short reference material and fewer roles.
|
||||
- Ollama is the preferred default. With failover enabled and an MLX folder set, a stage can switch to MLX if the primary fails before committing output. An MLX-only selection runs on the Mac. Remote Ollama and the existing compatible API also work through the chat router.
|
||||
- In **Settings → Model Library**, installed Ollama sizes come from the selected server. Installed MLX sizes come from local safetensors files. MLX catalog sizes come from file metadata for the pinned Hugging Face revision, and Ollama catalog sizes come from the registry manifest for the latest tag. A row shows **Size unknown** when the source does not report the required bytes or cannot be reached. Use **Preview** for the available architecture, quantization, context length, source, and other model details. **Active** marks the configured model. **In use** identifies the reporting backend during main-chat inference, including MLX failover.
|
||||
- Agent profiles and toggles live in the app's settings. The user prompt and final reply are stored in the existing SQLite chat history. Intermediate handoffs and the latest run status are kept in memory for the session.
|
||||
- Runs are interactive while AI Studio is open. Support in this version covers sequential handoffs, cancellation, and supervised MCP. Scheduled jobs, background workers, remote agent workers, and persistent run checkpoints are outside this version's scope.
|
||||
|
||||
## If a run stalls or produces a weak draft
|
||||
|
||||
- Check the current role beside the composer. Several roles can take longer than a single reply because each stage waits for the previous one.
|
||||
- Check **Settings → Models** for the active route and selected tag or folder. Use **Refresh Installed Models** when an Ollama server has changed.
|
||||
- If an approval appears, choose **Allow Once** or **Decline** to resume the run. If a required tool is absent, confirm it is connected in Toolbox and available to the specialist.
|
||||
- Use a smaller set of enabled roles and shorten large attachments if the backend runs out of context. Give each role a distinct responsibility and require a concrete output.
|
||||
- When a stage fails, check the chat status for the backend error and **Latest Run** for the last completed stage. After correcting the issue, send the task again.
|
||||
|
||||
## How execution is wired
|
||||
|
||||
The SwiftUI composer takes a snapshot of the enabled roles when you send. The chat model builds the existing inference context, then starts the workflow inside the chat's cancellable generation task. The same inference adapter constructs each stage's request, so the backend selection, credentials, model tag or MLX path, thinking options, and generation parameters follow the regular chat path.
|
||||
|
||||
The workflow gives each role a system instruction and adds bounded handoffs to the current request as reference material. This keeps ordinary chat history separate from intermediate work and keeps the turn format usable by Ollama and MLX chat templates. Each stage forwards its backend status to the UI. The reviewer streams into the ordinary chat transcript and uses the existing SQLite save and performance reporting paths.
|
||||
|
||||
The specialist sees numbered offers drawn from connected MCP tools, capped at 20 per run. The model may return a JSON object containing an offered tool number and an arguments object. AI Studio validates the shape and checks the offer, then waits for the user decision. The approved invocation goes through the existing MCP client. The next specialist generation receives a bounded response or a denial or failure message. The tool result is treated as reference material. The specialist's MCP access comes from the connected tool servers, so the capabilities depend on those servers.
|
||||
|
||||
Profile storage is independent of the backend and uses the same persistent settings mechanism as the built-in role toggles. This lets you change inference providers without recreating profiles. For implementation and regression tests, see `AgentWorkflow` in `Sources/Inference.swift`, the chat integration in `Sources/StudioModel.swift`, and `AgentWorkflowTests` in `Tests/StudioTests.swift`. Run `Scripts/test.sh` to start the fixture servers and exercise the Xcode scheme.
|
||||
+15
@@ -55,6 +55,21 @@ in Toolbox, review the returned passages, then attach the result to chat.
|
||||
The MCP index remains with its server. AI Studio's native **Knowledge Stacks**
|
||||
can separately index files you import in Workspace.
|
||||
|
||||
## Pegasus index management
|
||||
|
||||
Open **Settings → Knowledge Base** to view the Pegasus mount, source and chunk
|
||||
counts, free space, last run, and available progress. **Start Index Refresh**
|
||||
runs the existing incremental indexer against the mounted document folder.
|
||||
The job continues on Pegasus after the Settings window closes. It uses the
|
||||
existing `pegasus` SSH alias and key-based authentication. If indexing is already
|
||||
running, wait for it to finish before starting another refresh.
|
||||
|
||||
General chat questions use automatic web lookup by default when **Web Search
|
||||
& Page Retrieval** is enabled in **Settings → Toolbox**. Requests about
|
||||
private or selected workspace material skip automatic search. Explicit web
|
||||
search remains available. The chat's knowledge lookup status and source
|
||||
disclosure are shown when the chat debug setting is on.
|
||||
|
||||
## Implement a server
|
||||
|
||||
Use an official MCP SDK. For stdio, communicate in newline-delimited UTF-8
|
||||
|
||||
+49
-14
@@ -1,8 +1,20 @@
|
||||
# Fine-tune a model for use in AI Studio
|
||||
|
||||
AI Studio can download and run MLX checkpoints from Hugging Face and register
|
||||
local MLX model folders. Training is currently an external MLX LM workflow.
|
||||
The app does not yet provide a Clone or Train button.
|
||||
local MLX model folders. Training and conversion run locally using the MLX LM tools.
|
||||
Use the repository's `Scripts/train-mlx.py` to validate a local chat dataset, train and evaluate an adapter, and fuse a new checkpoint from Terminal.
|
||||
|
||||
## Use the tools in AI Studio
|
||||
|
||||
1. Open **Settings → Model Library → MLX → MLX Tools…**. For an installed model, use **Clone & Train…** to preselect its weights.
|
||||
2. Use **Install MLX Tools** once. It uses a native Apple Silicon Python 3.11 or newer to install MLX LM with its training dependencies into a dedicated AI Studio environment. If automatic selection picks the wrong interpreter, use **Choose Python…**.
|
||||
3. Use **Clone Base…** to write a separate copy to a new folder and add it to the library. Training can also use the original checkpoint while writing adapter weights to a separate run folder.
|
||||
4. Choose a dataset folder and a run folder. Use **Validate Dataset**, **Train Adapter**, and **Evaluate**. Use **Fuse and Register** to create and register the final checkpoint. The run folder contains the adapter at `adapter` and the fused output at `trained-model`. Pick a fresh run folder for a new experiment.
|
||||
5. Read errors and training output in the workshop. **Stop** ends the current operation. If stopping a run leaves partial output in its folder, choose a new destination before retrying.
|
||||
|
||||
The workshop also has **Convert to MLX**. Choose a compatible original checkpoint folder, or enter a Hugging Face repo ID and optionally pin its revision. Choose a new destination. The 4-bit option reduces weight size. A successful result appears in the MLX library and can be used as a training base.
|
||||
|
||||
In the Ollama library, an installed model's **Tools → Clone…** creates a new tag on the configured server. **Tools → Convert to MLX…** opens the same conversion workflow using the original Hugging Face checkpoint. The MLX LM converter accepts compatible model checkpoints. A packaged Ollama GGUF blob requires a separate conversion approach.
|
||||
|
||||
## 1. Choose the base model
|
||||
|
||||
@@ -21,6 +33,19 @@ an explicit revision. For a gated repository, request access and authenticate
|
||||
using the Hub CLI before downloading. AI Studio's built-in catalog currently
|
||||
downloads public MLX Community checkpoints.
|
||||
|
||||
To download a separate copy, run this from your training project after
|
||||
installing the Hugging Face Hub CLI. Take the repository and full commit
|
||||
from the model preview in AI Studio and choose a new local folder.
|
||||
|
||||
```sh
|
||||
hf download OWNER/REPO --revision FULL_COMMIT_SHA --local-dir ./base-model
|
||||
```
|
||||
|
||||
To copy an Ollama model tag on the server configured for the Ollama CLI, use
|
||||
`ollama cp SOURCE:TAG MY-MODEL:TAG`. This copies the inference model under a
|
||||
new name with the same weights. To fine-tune it, obtain the matching training
|
||||
checkpoint from the publisher and record its revision.
|
||||
|
||||
## 2. Prepare your local dataset
|
||||
|
||||
Create a dataset folder with `train.jsonl`, `valid.jsonl`, and `test.jsonl`.
|
||||
@@ -50,7 +75,7 @@ Record the installed version with the experiment so you can reproduce it.
|
||||
```sh
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
python -m pip install mlx-lm
|
||||
python -m pip install "mlx-lm[train]"
|
||||
python -m pip show mlx-lm
|
||||
```
|
||||
|
||||
@@ -67,6 +92,25 @@ mlx_lm.generate --model "$BASE" --adapter-path ./adapter \
|
||||
--prompt "Review this change for missing validation."
|
||||
```
|
||||
|
||||
The repository runner offers the same local workflow with dataset validation
|
||||
and checks for new output folders. Run these from your training project with
|
||||
the MLX environment activated.
|
||||
|
||||
```sh
|
||||
RUNNER="$HOME/Developer/Applications/AIStudio/Scripts/train-mlx.py"
|
||||
python "$RUNNER" validate --data ./dataset
|
||||
python "$RUNNER" train --base "$BASE" --data ./dataset --adapter ./adapter-smoke
|
||||
python "$RUNNER" evaluate --base "$BASE" --data ./dataset --adapter ./adapter-smoke
|
||||
python "$RUNNER" fuse --base "$BASE" --adapter ./adapter-smoke --out ./trained-model
|
||||
```
|
||||
|
||||
The runner expects text chat examples and rejects the same prompt history
|
||||
across splits. It starts with 50 iterations, batch size 1, and four adapted
|
||||
layers. Use `--iters` and `--layers` to change the smoke run and choose a new
|
||||
adapter folder for each experiment. Prompt masking trains against the final
|
||||
assistant response. On a quantized base, MLX LM uses QLoRA. A smoke run checks
|
||||
the pipeline. Use a held-out evaluation to judge whether to keep the adapter.
|
||||
|
||||
Compare base and adapter answers on the same held-out examples. Check
|
||||
grounding, task accuracy, style, and regressions outside the target task.
|
||||
Use a small first run to check memory and verify the checkpoint supports
|
||||
@@ -95,15 +139,6 @@ training configuration, evaluation and limitations in the model card. A Hub
|
||||
repository can store the adapter or fused checkpoint separately from the base.
|
||||
Keep it private unless you intend to publish it.
|
||||
|
||||
## Proposed AI Studio integration
|
||||
|
||||
A **Create Training Variant** action should create a new local record tied to
|
||||
the pinned base revision. A dataset picker should validate JSONL and preview
|
||||
the splits. A training screen should show settings, progress, loss, cancellation
|
||||
and checkpoints. Once a run completes, present a side-by-side evaluation and
|
||||
a **Register Trained Model** action. Start with the MLX LM worker in a dedicated
|
||||
environment and record the runtime version and exact inputs. Set no automatic
|
||||
upload destination.
|
||||
|
||||
Sources: [MLX LM LoRA guide](https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/LORA.md) ·
|
||||
[Hugging Face Hub download guide](https://huggingface.co/docs/huggingface_hub/guides/download)
|
||||
[Hugging Face Hub download guide](https://huggingface.co/docs/huggingface_hub/guides/download) ·
|
||||
[Ollama import guide](https://docs.ollama.com/import)
|
||||
|
||||
Reference in New Issue
Block a user