Multi-agent workflows

Last updated:

On this page

Combine staik models in agent flows. Each model has its strengths — use the right model for the right task:

ModelStrengthsAgent role
qwen3.6:35b-a3bCoding, complex tasksCoder, problem solver
gemma4:31bAccuracy, review, language, visionReviewer, orchestrator, image analysis
qwen3.5:9bFast, simpler tasksRouting, summarization

1. Coder + reviewer loop

Two agents take turns: one codes, one reviews. The loop continues until the reviewer approves the result.

text
Coder (qwen3.6:35b) → writes code

Reviewer (gemma4:31b) → reviews + gives feedback

Approved? → Yes: done | No: back to coder
python
from crewai import Agent, Task, Crew, LLM

coder_llm = LLM(
    model="openai/qwen3.6:35b-a3b",
    base_url="https://api.staik.se/v1",
    api_key="sk-st-your-key",
)
reviewer_llm = LLM(
    model="openai/gemma4:31b",
    base_url="https://api.staik.se/v1",
    api_key="sk-st-your-key",
)

coder = Agent(
    role="Developer",
    goal="Write clean, working Python code",
    backstory="Senior Python developer with focus on readability.",
    llm=coder_llm,
)
reviewer = Agent(
    role="Code Reviewer",
    goal="Review code for bugs, style and correctness",
    backstory="Meticulous code reviewer who catches edge cases.",
    llm=reviewer_llm,
)

code_task = Task(
    description="Write a Python function that validates email addresses with regex.",
    expected_output="A correct Python function with docstring.",
    agent=coder,
)
review_task = Task(
    description="Review the code. Check edge cases, security, and readability.",
    expected_output="Approved or list of improvement suggestions.",
    agent=reviewer,
)

crew = Crew(agents=[coder, reviewer], tasks=[code_task, review_task])
print(crew.kickoff())

2. Orchestrator

A central agent breaks down the task and delegates parts to specialized agents using different models.

text
Orchestrator (gemma4:31b) → analyzes the task
  ├→ Coder (qwen3.6:35b) → writes implementation
  ├→ Tester (qwen3.5:9b) → writes tests (fast)
  └→ Orchestrator → compiles results
python
from crewai import Agent, Task, Crew, Process, LLM

def staik_llm(model: str) -> LLM:
    return LLM(
        model=f"openai/{model}",
        base_url="https://api.staik.se/v1",
        api_key="sk-st-your-key",
    )

orchestrator = Agent(role="Project Manager",
                     goal="Break down tasks and coordinate the team",
                     llm=staik_llm("gemma4:31b"))
coder = Agent(role="Developer",
              goal="Implement features based on specifications",
              llm=staik_llm("qwen3.6:35b-a3b"))
tester = Agent(role="QA Engineer",
               goal="Write comprehensive test cases",
               llm=staik_llm("qwen3.5:9b"))

task = Task(
    description="Build a REST API endpoint for user registration with validation and tests.",
    expected_output="Complete implementation with tests.",
    agent=orchestrator,
)

crew = Crew(
    agents=[orchestrator, coder, tester],
    tasks=[task],
    process=Process.hierarchical,
    manager_agent=orchestrator,
)
print(crew.kickoff())

3. Human-in-the-loop

The agent works autonomously but pauses at critical steps for human approval.

python
from openai import OpenAI

client = OpenAI(base_url="https://api.staik.se/v1", api_key="sk-st-your-key")

def generate_and_review(task: str) -> str:
    # Step 1: The agent generates a proposal
    proposal = client.chat.completions.create(
        model="qwen3.6:35b-a3b",
        messages=[
            {"role": "system", "content": "You are a senior developer. Generate a proposal."},
            {"role": "user", "content": task},
        ],
    ).choices[0].message.content

    print(f"\n--- PROPOSAL ---\n{proposal}\n")

    # Step 2: Human reviews
    feedback = input("Approve (enter) or give feedback: ")
    if not feedback:
        return proposal

    # Step 3: The agent revises based on feedback
    return client.chat.completions.create(
        model="qwen3.6:35b-a3b",
        messages=[
            {"role": "system", "content": "Revise your proposal based on the feedback."},
            {"role": "user", "content": task},
            {"role": "assistant", "content": proposal},
            {"role": "user", "content": feedback},
        ],
    ).choices[0].message.content

print(generate_and_review("Design a database schema for an e-commerce app."))

4. Pipeline

Sequential flow where each step is processed by a specialized model — output from one step becomes input to the next.

text
Write (qwen3.6:35b) → Review (gemma4:31b) → Translate (qwen3.5:9b)
python
from openai import OpenAI

client = OpenAI(base_url="https://api.staik.se/v1", api_key="sk-st-your-key")

def pipeline_step(model: str, system: str, content: str) -> str:
    return client.chat.completions.create(
        model=model,
        messages=[
            {"role": "system", "content": system},
            {"role": "user", "content": content},
        ],
    ).choices[0].message.content

draft = pipeline_step(
    "qwen3.6:35b-a3b",
    "You are a technical writer. Write clear documentation.",
    "Document how to set up a WebSocket server in Python.",
)
reviewed = pipeline_step(
    "gemma4:31b",
    "You are an editor. Improve text without changing technical content.",
    draft,
)
translated = pipeline_step(
    "qwen3.5:9b",
    "Translate to fluent Swedish. Keep code examples unchanged.",
    reviewed,
)
print(translated)

Frameworks

staik works out of the box with popular frameworks — just change the base_url and API key:

python
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

llm = ChatOpenAI(
    model="gemma4:31b",
    base_url="https://api.staik.se/v1",
    api_key="sk-st-your-key",
)

response = llm.invoke([HumanMessage(content="Write a haiku about Stockholm")])
print(response.content)

Tools in your agents

Give the agents tool calling and built-in web search — no need to build search and tool infrastructure yourself.