Repository navigation
Add Asimi support as a new harness #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeonHibnik
wants to merge
5
commits into
main
Choose a base branch
from
feat/asimi-harness-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b1b90c3
feat: add Asimi support as a new harness
LeonHibnik 850f55c
feat: update Asimi harness configuration and add live report
LeonHibnik 28edede
feat: add Asimi support as a new harness
nonam3e a69ccfd
Merge main and asimi harness follow-up work
nonam3e b427d6b
Retrying the Asimi live probe on transient failures
nonam3e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { commandExists } from "../../install.js"; | ||
| import type { ZroModel } from "../constants.js"; | ||
| import type { LaunchContext, ToolModule } from "../types.js"; | ||
|
|
||
| // Asimi talks to any OpenAI-compatible endpoint through its "openai" provider: | ||
| // OPENAI_API_KEY provides the key and OPENAI_BASE_URL the endpoint (asimi | ||
| // normalizes the base URL itself, stripping the /v1 suffix before its client | ||
| // re-appends it). A custom provider id would resolve ZRO_API_KEY/ZRO_BASE_URL | ||
| // by convention, but asimi only collects keys from the environment for its | ||
| // standard providers, so the openai route is the one that works headless. | ||
| // ASIMI_MODEL/ASIMI_REASONING_EFFORT env overrides beat its config file; the | ||
| // --model flag beats both. | ||
| const ASIMI_PROVIDER = "openai"; | ||
| const ASIMI_PROVIDER_ENV_KEY = "ASIMI_PROVIDER"; | ||
| const ASIMI_MODEL_ENV_KEY = "ASIMI_MODEL"; | ||
| const ASIMI_REASONING_EFFORT_ENV_KEY = "ASIMI_REASONING_EFFORT"; | ||
| const OPENAI_API_KEY_ENV_KEY = "OPENAI_API_KEY"; | ||
| const OPENAI_BASE_URL_ENV_KEY = "OPENAI_BASE_URL"; | ||
|
|
||
| // Asimi only accepts low|medium|high. Catalog levels outside that set (off, | ||
| // minimal, xhigh) map to the nearest accepted effort; this can differ from | ||
| // what the server sent, so the env var is omitted entirely when there is no | ||
| // sensible mapping rather than guessing. | ||
| const EFFORT_BY_PI_LEVEL: Partial<Record<ZroModel["reasoning"]["levels"][number]["piLevel"], string>> = { | ||
| minimal: "low", | ||
| low: "low", | ||
| medium: "medium", | ||
| high: "high", | ||
| xhigh: "high" | ||
| }; | ||
|
|
||
| // Asimi runs the agent shell in a podman sandbox and builds the sandbox image | ||
| // through the Justfile its :init command generates, so both must be on PATH. | ||
| const SANDBOX_DEPENDENCIES = ["podman", "just"] as const; | ||
|
|
||
| async function ensureSandboxDependencies(ctx: LaunchContext): Promise<void> { | ||
| const missing: string[] = []; | ||
| for (const dependency of SANDBOX_DEPENDENCIES) { | ||
| if (!(await commandExists(dependency, ctx.env, ctx.platform))) missing.push(dependency); | ||
| } | ||
| if (missing.length > 0) { | ||
| throw new Error( | ||
| `Asimi needs ${missing.join(" and ")} to run its shell in a podman sandbox. ` + | ||
| "Install it (podman: https://podman.io/docs/installation, just: https://github.com/casey/just) " + | ||
| "and run zro asimi again." | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const asimiTool: ToolModule = { | ||
| id: "asimi", | ||
| label: "Asimi", | ||
| async launch(ctx) { | ||
| await ensureSandboxDependencies(ctx); | ||
| const model = ctx.models.find((candidate) => candidate.id === ctx.model); | ||
| const env: Record<string, string> = { | ||
| [OPENAI_API_KEY_ENV_KEY]: ctx.apiKey, | ||
| [OPENAI_BASE_URL_ENV_KEY]: ctx.inferenceBaseUrl, | ||
| [ASIMI_PROVIDER_ENV_KEY]: ASIMI_PROVIDER, | ||
| [ASIMI_MODEL_ENV_KEY]: ctx.model | ||
| }; | ||
| const effort = model ? reasoningEffort(model) : undefined; | ||
| if (effort) { | ||
| env[ASIMI_REASONING_EFFORT_ENV_KEY] = effort; | ||
| } | ||
| return { | ||
| tool: "asimi", | ||
| label: "Asimi", | ||
| model: ctx.model, | ||
| command: "asimi", | ||
| args: ["--model", ctx.model, "--provider", ASIMI_PROVIDER, ...ctx.extraArgs], | ||
| env, | ||
| message: "Launch Asimi with Zro" | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| export function reasoningEffort(model: ZroModel): string | undefined { | ||
| const level = model.reasoning.levels.find( | ||
| (candidate) => candidate.id === model.reasoning.defaultLevel | ||
| ); | ||
| return level ? EFFORT_BY_PI_LEVEL[level.piLevel] : undefined; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import fs from "node:fs/promises"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { PassThrough } from "node:stream"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { asimiTool, reasoningEffort } from "../src/engine/tools/asimi.js"; | ||
| import type { LaunchContext } from "../src/engine/types.js"; | ||
| import { TEST_MODELS, fakeSandboxBinDir } from "./fixtures.js"; | ||
|
|
||
| describe("Asimi adapter", () => { | ||
| it("launches via provider env conventions without writing config files", async () => { | ||
| const home = await fs.mkdtemp(path.join(os.tmpdir(), "zro-asimi-home-")); | ||
| const ctx = context(home, { | ||
| PATH: await fakeSandboxBinDir(), | ||
| OTEL_EXPORTER_OTLP_ENDPOINT: "https://collector.invalid", | ||
| }); | ||
| const plan = await asimiTool.launch(ctx); | ||
|
|
||
| expect(plan).toMatchObject({ | ||
| tool: "asimi", | ||
| label: "Asimi", | ||
| command: "asimi", | ||
| model: "glm-5.3", | ||
| args: ["--model", "glm-5.3", "--provider", "openai", "--print", "hello"], | ||
| }); | ||
| expect(plan.files).toBeUndefined(); | ||
| expect(plan.env).toMatchObject({ | ||
| OPENAI_API_KEY: "sk-asimi-secret", | ||
| OPENAI_BASE_URL: "https://zro.moonmath.ai/v1", | ||
| ASIMI_PROVIDER: "openai", | ||
| ASIMI_MODEL: "glm-5.3", | ||
| ASIMI_REASONING_EFFORT: "high", | ||
| }); | ||
| expect(Object.values(plan.env ?? {})).not.toContain("collector.invalid"); | ||
| }); | ||
|
|
||
| it("rejects the launch when podman or just is missing from PATH", async () => { | ||
| const home = await fs.mkdtemp(path.join(os.tmpdir(), "zro-asimi-home-")); | ||
| const ctx = context(home, { PATH: "/nonexistent-zro-asimi" }); | ||
| await expect(asimiTool.launch(ctx)).rejects.toThrow(/podman/); | ||
| }); | ||
|
|
||
| it("maps reasoning levels to asimi's low|medium|high efforts", () => { | ||
| for (const model of TEST_MODELS) { | ||
| const effort = reasoningEffort(model); | ||
| expect(["low", "medium", "high", undefined]).toContain(effort); | ||
| } | ||
| }); | ||
|
|
||
| it("omits the reasoning effort when no level maps cleanly", async () => { | ||
| const model = { | ||
| ...TEST_MODELS[0], | ||
| reasoning: { | ||
| defaultLevel: "off", | ||
| levels: [{ id: "off", description: "off", piLevel: "off" as const, openCodeOptions: {} }], | ||
| }, | ||
| }; | ||
| expect(reasoningEffort(model)).toBeUndefined(); | ||
| const home = await fs.mkdtemp(path.join(os.tmpdir(), "zro-asimi-home-")); | ||
| const ctx = context(home, { PATH: await fakeSandboxBinDir() }); | ||
| ctx.models = [model]; | ||
| const plan = await asimiTool.launch(ctx); | ||
| expect(plan.env?.ASIMI_REASONING_EFFORT).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| function context(homeDir: string, env: NodeJS.ProcessEnv = {}): LaunchContext { | ||
| return { | ||
| apiKey: "sk-asimi-secret", | ||
| apiKeySource: "env", | ||
| inferenceRoot: "https://zro.moonmath.ai", | ||
| inferenceBaseUrl: "https://zro.moonmath.ai/v1", | ||
| mcpUrl: "https://zro.moonmath.ai/mcp/zro", | ||
| noAuth: false, | ||
| env, | ||
| model: "glm-5.3", | ||
| models: TEST_MODELS, | ||
| extraArgs: ["--print", "hello"], | ||
| homeDir, | ||
| cwd: homeDir, | ||
| tempDir: path.join(homeDir, "session"), | ||
| platform: "linux", | ||
| stdin: new PassThrough(), | ||
| stdout: new PassThrough(), | ||
| stderr: new PassThrough(), | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Reasoning-effort mapping test can never fail
This test only asserts
expect(["low", "medium", "high", undefined]).toContain(effort)for each fixture model, which is satisfied by the return type itself — it passes even ifreasoningEffortreturned a wrong value or a constant.TEST_MODELSonly exercisesxhigh(glm-5.3, defaultLevel "max") andhigh(kimi-k3), so theminimal → low,low → low, andmedium → mediumrows ofEFFORT_BY_PI_LEVELinsrc/engine/tools/asimi.tsare never asserted.Suggested fix: add explicit per-level expectations (e.g. build models with each
defaultLevel/piLevelpair and assert the exact mapped effort) so a mapping regression is caught.