Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
examples(contract-review-agent): consolidate generative roles on Qwen3.5-4B
svonavad2079cef6908
diff --git a/examples/contract-review-agent/README.md b/examples/contract-review-agent/README.mdindex db9b8ab7e..094397820 100644--- a/examples/contract-review-agent/README.md+++ b/examples/contract-review-agent/README.md@@ -11,10 +11,10 @@ Every value below is a real model in the [SIE catalog](https://superlinked.com/m| Role in the agent | SIE model | SIE function ||---|---|---|| Triage — classify the document type | `Qwen/Qwen3-0.6B` | chat |-| **Orchestrator** — plan, call tools, assemble the review | `Qwen/Qwen3-4B-Instruct-2507` (alias `code`) | chat + tools + JSON schema |+| **Orchestrator** — plan, call tools, assemble the review | `Qwen/Qwen3.5-4B` | chat + tools + JSON schema || Vision — read the scanned signature page | `Qwen/Qwen3.5-4B` | chat + image |-| Reasoning sub-agent — clause-risk analysis | `Qwen/Qwen3-4B-Instruct-2507` (↑ `Qwen3.5-4B` / `Qwen3.6-27B` where served) | chat |-| Text-to-SQL — query the obligations DB | `defog/sqlcoder-7b-2` | completions |+| Reasoning sub-agent — clause-risk analysis | `Qwen/Qwen3.5-4B` (↑ `Qwen3.6-27B` where served) | chat |+| Text-to-SQL — query the obligations DB | `Qwen/Qwen3.5-4B` (↑ `Qwen3-4B-Instruct-2507`; or `defog/sqlcoder-7b-2` with `sql.mode: completions`) | chat || Guardrail — safety / prompt-injection | `ibm-granite/granite-guardian-3.0-2b` (alias `guard`) | chat || OCR — scanned page → markdown | `lightonai/LightOnOCR-2-1B` | extract || Clause search — dense embeddings | `BAAI/bge-m3` | encode |@@ -35,12 +35,12 @@ set_tracing_disabled(True) # ...and we never phone home with traceAfter that, each `Agent` just names the SIE model it should run on:```python-Agent(name="Risk Analyst", model=OpenAIChatCompletionsModel("Qwen/Qwen3-4B-Instruct-2507", openai_client=client), ...)+Agent(name="Risk Analyst", model=OpenAIChatCompletionsModel("Qwen/Qwen3.5-4B", openai_client=client), ...)```The flow is **two agents** (which is what keeps a small open model reliable):-1. An **investigator** (on `Qwen3-4B-Instruct`) with seven tools and **no** structured `output_type` — so it can't short-circuit to a hallucinated answer and instead must call tools to learn anything about the contract:+1. An **investigator** (on `Qwen3.5-4B`) with seven tools and **no** structured `output_type` — so it can't short-circuit to a hallucinated answer and instead must call tools to learn anything about the contract:- `classify_document` (triage) · `read_signature_page` (vision) · `analyze_clause_risks` (delegates to the reasoning **sub-agent**) — generative LLMs- `ocr_signature_page` · `extract_entities` (`extract`), `search_clauses` (`encode` + `score`), `query_obligations_db` (`completions`) — retrieval & extraction- a `granite-guardian` **input guardrail** screens the request first (and fails open, logged, if the guard model is unavailable).@@ -69,8 +69,9 @@ uv run review # uv run review --list to see availableuv run review --contract <slug> # review a specific one```-> **GPU sizing.** `reasoning` defaults to `Qwen/Qwen3-4B-Instruct-2507` (reliable, fast) so the demo-> runs on a single mid-size GPU; swap in the newer `Qwen/Qwen3.5-4B` or the stronger `Qwen/Qwen3.6-27B` (H100/RTX PRO 6000) where the cluster serves them. A cold+> **GPU sizing.** The generative roles (`orchestrator`, `vision`, `reasoning`, `sql`) are consolidated on+> `Qwen/Qwen3.5-4B`, so one warm 4B vision+text model runs the demo on a single mid-size GPU; bump+> `reasoning`/`sql` to the stronger `Qwen/Qwen3.6-27B` (H100/RTX PRO 6000) where the cluster serves it. A cold> cluster pays a one-time load per model on first use; the agent retries the "still> provisioning" responses under `cluster.provision_timeout_s`. Keep bundles warm> (`minReplicas: 1`) to skip the wait — and any model the cluster can't serve degrades@@ -104,8 +105,8 @@ The default corpus is **[CUAD](https://www.atticusprojectai.org/cuad/)** (Contra## Notes-- Chat completions, tool calling, JSON-schema structured output, vision, and `/v1/completions` (for `sqlcoder`) are all served over SIE's OpenAI-compatible API.-- `sqlcoder-7b-2` is a completion model used with its native text-to-SQL template; for higher accuracy you can instead point `sql` at the `code`-aliased instruct model.+- Chat completions, tool calling, JSON-schema structured output, vision, and `/v1/completions` (set `sql.mode: completions` to route SQL through a completion-only model like `sqlcoder`) are all served over SIE's OpenAI-compatible API.+- Text-to-SQL runs on `Qwen/Qwen3.5-4B` over chat by default. For stronger SQL, point `sql` at `Qwen/Qwen3-4B-Instruct-2507` (SIE's measured-best 4B text-to-SQL, Spider ≈0.70); to demo the completion path, set `sql: "defog/sqlcoder-7b-2"` with `sql.mode: completions`.- This is a demo of inference orchestration, **not legal advice**.Apache-2.0, like the rest of SIE.diff --git a/examples/contract-review-agent/config.yaml b/examples/contract-review-agent/config.yamlindex fc16f707a..ccf409202 100644--- a/examples/contract-review-agent/config.yaml+++ b/examples/contract-review-agent/config.yaml@@ -12,13 +12,16 @@ cluster:# Every value is a real model in the SIE catalog (https://superlinked.com/models).# Swap any line to try a different model; no other code changes.models:- # Generative LLMs — the agent "brains" (chat / tools / structured output):- triage: "Qwen/Qwen3-0.6B" # fast, cheap doc-type classifier (no tools)- orchestrator: "Qwen/Qwen3-4B-Instruct-2507" # plans, calls tools, assembles output (alias: code)+ # Generative LLMs — the agent "brains" (chat / tools / structured output).+ # Consolidated onto Qwen/Qwen3.5-4B for now: one warm 4B vision+text model+ # does the planning, vision, reasoning, and SQL jobs. Branch out per role+ # from there (see the ↑ hints) as the cluster grows.+ triage: "Qwen/Qwen3-0.6B" # fast, cheap doc-type classifier (kept tiny on purpose; no tools)+ orchestrator: "Qwen/Qwen3.5-4B" # plans, calls tools, assembles output (chat + tools + JSON schema)vision: "Qwen/Qwen3.5-4B" # reads scanned / signature pages (text + image)- reasoning: "Qwen/Qwen3-4B-Instruct-2507" # clause-risk analysis (reliable, fast); swap to newer Qwen/Qwen3.5-4B or stronger Qwen/Qwen3.6-27B where the cluster serves them- sql: "defog/sqlcoder-7b-2" # text-to-SQL specialist (completions + native template)- guard: "ibm-granite/granite-guardian-3.0-2b" # safety / prompt-injection guardrail (alias: guard)+ reasoning: "Qwen/Qwen3.5-4B" # clause-risk analysis; ↑ Qwen/Qwen3.6-27B on an H100-class cluster+ sql: "Qwen/Qwen3.5-4B" # text-to-SQL via chat (see sql.mode); ↑ Qwen/Qwen3-4B-Instruct-2507 for stronger SQL, or defog/sqlcoder-7b-2 with sql.mode=completions+ guard: "ibm-granite/granite-guardian-3.0-2b" # safety / prompt-injection guardrail (specialist; alias: guard)# Retrieval + extraction tools (encode / score / extract):ocr: "lightonai/LightOnOCR-2-1B" # scanned PDF / image -> markdown (latest OCR model)embed: "BAAI/bge-m3" # dense embeddings for clause search@@ -34,3 +37,10 @@ guard:# granite-guardian emits a "yes" (unsafe) / "no" (safe) verdict. Trip the# guardrail when P(unsafe) clears this threshold. 0.5 is recall-biased.threshold: 0.5++# Text-to-SQL calling convention. Chat/instruct models (Qwen3.5-4B,+# Qwen3-4B-Instruct) take a chat prompt; completion-only specialists like+# defog/sqlcoder-7b-2 need their native template over /v1/completions — set+# mode: completions when you point `sql` at one of those.+sql:+ mode: "chat" # "chat" | "completions"diff --git a/examples/contract-review-agent/contract_review_agent/cli.py b/examples/contract-review-agent/contract_review_agent/cli.pyindex eeb310ce8..48e6bc801 100644--- a/examples/contract-review-agent/contract_review_agent/cli.py+++ b/examples/contract-review-agent/contract_review_agent/cli.py@@ -27,7 +27,7 @@ ROLE_INFO = [("triage", "Classify the document type (fast)", "chat"),("vision", "Read the scanned signature page", "chat + image"),("reasoning", "Clause-risk specialist (sub-agent)", "chat"),- ("sql", "Text-to-SQL over the obligations DB", "completions"),+ ("sql", "Text-to-SQL over the obligations DB", "chat"),("guard", "Safety / prompt-injection guardrail", "chat"),("ocr", "Scanned page → markdown", "extract"),("embed", "Clause search (embeddings)", "encode"),@@ -43,6 +43,8 @@ def _print_catalog(cfg: dict) -> None:table.add_column("SIE function", style="magenta")table.add_column("Job")for role, job, fn in ROLE_INFO:+ if role == "sql": # the SQL tool's wire path follows sql.mode (chat | completions)+ fn = (cfg.get("sql") or {}).get("mode", "chat")table.add_row(role, cfg["models"][role], fn, job)console.print(table)diff --git a/examples/contract-review-agent/contract_review_agent/tools.py b/examples/contract-review-agent/contract_review_agent/tools.pyindex 014e6ff07..9eca475ad 100644--- a/examples/contract-review-agent/contract_review_agent/tools.py+++ b/examples/contract-review-agent/contract_review_agent/tools.py@@ -243,7 +243,7 @@ async def search_clauses(ctx: RunContextWrapper[AppContext], query: str) -> str:# ──────────────────────────────────────────────────────────────────────────-# Text-to-SQL tool (completion-only specialist model)+# Text-to-SQL tool (chat by default; completion-template mode for specialists)# ──────────────────────────────────────────────────────────────────────────_SQLCODER_PROMPT = """### TaskGenerate a SQLite SQL query to answer [QUESTION]{question}[/QUESTION]@@ -260,6 +260,21 @@ The query will run on a database with this schema:Given the database schema, here is the SQLite query that answers [QUESTION]{question}[/QUESTION]:"""+# Chat-mode SQL prompt for instruct/chat models (Qwen3.5-4B, Qwen3-4B-Instruct).+_SQL_CHAT_SYSTEM = (+ "You are a text-to-SQL engine for SQLite. Given the schema and a question, "+ "reply with ONE SQLite SELECT statement and nothing else — no prose, no "+ "explanation, no markdown fences. Today's date is {today}. Dates are stored "+ "as ISO-8601 text; use SQLite date functions (e.g. date('now'), date(due_date))."+)++_SQL_CHAT_USER = """Database schema:+{schema}++Question: {question}++SQLite query:"""+def _clean_sql(raw: str) -> str:sql = raw.strip()@@ -290,9 +305,23 @@ async def query_obligations_db(ctx: RunContextWrapper[AppContext], question: stroutstanding payments by counterparty'."""app = ctx.contextmodel = app.cfg["models"]["sql"]- prompt = _SQLCODER_PROMPT.format(question=question, schema=SCHEMA_DDL, today=TODAY)- res = await complete_once(app, model, prompt, max_tokens=256, stop=[";", "```", "\n\n\n"])- app.ledger.record("Text-to-SQL", model, "completions",+ # Chat/instruct models take a chat prompt; completion-only specialists (e.g.+ # defog/sqlcoder-7b-2) use their native template over /v1/completions. Default+ # is chat — set sql.mode=completions in config.yaml to use a completion model.+ mode = (app.cfg.get("sql") or {}).get("mode", "chat")+ if mode == "completions":+ prompt = _SQLCODER_PROMPT.format(question=question, schema=SCHEMA_DDL, today=TODAY)+ res = await complete_once(app, model, prompt, max_tokens=256, stop=[";", "```", "\n\n\n"])+ else:+ res = await chat_once(+ app, model,+ [+ {"role": "system", "content": _SQL_CHAT_SYSTEM.format(today=TODAY)},+ {"role": "user", "content": _SQL_CHAT_USER.format(schema=SCHEMA_DDL, question=question)},+ ],+ max_tokens=256,+ )+ app.ledger.record("Text-to-SQL", model, mode,warmup_s=res.provision_s, latency_s=res.gen_s,sent=_tok(res.prompt_tokens), got=_tok(res.completion_tokens), throughput=_tps(res))