DEV Community

shashank ms
shashank ms

Posted on

Solving Complex Tasks with LLMs

We are building a research orchestrator that decomposes complex questions into sub-tasks, gathers facts through tool calls, and synthesizes a structured report. This pattern works for competitive analysis, technical due diligence, or any workflow where a single LLM pass is not enough. Because Oxlo.ai charges per request rather than per token, running multiple planning and synthesis passes on long contexts does not inflate cost.

What you'll need

Step 1: Configure the client and the research task

I initialize the OpenAI-compatible client pointing at Oxlo.ai and define the complex question we want answered. I use llama-3.3-70b as a reliable general-purpose model for the initial setup.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

RESEARCH_QUESTION = (
    "Evaluate the trade-offs between lithium-ion and solid-state batteries "
    "for electric aviation, considering energy density, safety, and manufacturing scalability."
)

Step 2: Create the task planner

I need the model to break the complex question into specific sub-tasks. I prompt for JSON so I can parse the plan programmatically. Qwen 3 32B handles structured reasoning well, so I use it here.

import json

PLANNER_PROMPT = """You are a task planner. Break the user's complex research question into 3 to 5 specific sub-tasks that can be researched independently. Output strictly as a JSON array of strings with no markdown formatting."""

def plan_tasks(question: str) -> list[str]:
    response = client.chat.completions.create(
        model="qwen-3-32b",
        messages=[
            {"role": "system", "content": PLANNER_PROMPT},
            {"role": "user", "content": question},
        ],
        temperature=0.2,
    )
    content = response.choices[0].message.content.strip()
    if content.startswith("

```"):
        content = content.split("\n", 1)[1].rsplit("```

", 1)[0].strip()
    return json.loads(content)

sub_tasks = plan_tasks(RESEARCH_QUESTION)
print("Planned tasks:", sub_tasks)

Step 3: Define the knowledge base tool

To keep this fully runnable without external search APIs, I simulate a knowledge base lookup. The tool accepts a query string and returns relevant facts from an in-memory dictionary.

KNOWLEDGE_BASE = {
    "lithium-ion energy density aviation": "Li-ion packs for aviation achieve 250-300 Wh/kg at the cell level, but pack-level drops to 150-180 Wh/kg due to cooling and structural overhead.",
    "solid-state energy density aviation": "Solid-state lab cells have reached 400-500 Wh/kg, with projections of 350-400 Wh/kg at the pack level by 2030.",
    "lithium-ion safety aviation": "Thermal runaway remains a risk. Aviation certification requires redundant containment and active cooling, adding weight.",
    "solid-state safety aviation": "Solid electrolytes eliminate flammable liquid electrolytes, significantly reducing fire risk and simplifying thermal management.",
    "lithium-ion manufacturing scalability": "Gigafactories exist today. Scaling to aviation volumes requires only incremental capacity, not new chemistries.",
    "solid-state manufacturing scalability": "Manufacturing is still pilot-scale. Dry electrode processing and ceramic electrolyte handling remain yield bottlenecks.",
}

def search_knowledge_base(query: str) -> str:
    query_lower = query.lower()
    for key, value in KNOWLEDGE_BASE.items():
        if all(word in query_lower for word in key.split()[:3]):
            return value
    return "No direct data available. Proceed with general reasoning."

TOOL_SCHEMA = {
    "type": "function",
    "function": {
        "name": "search_knowledge_base",
        "description": "Search the technical knowledge base for facts related to the query.",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "Specific search query."}
            },
            "required": ["query"],
        },
    },
}

Step 4: Build the execution loop

Now I run each sub-task through an agent that can call the search tool. I use function calling with Oxlo.ai's chat completions endpoint. The loop handles the tool call, executes the local Python function, and feeds the result back to the model.

import json

EXECUTOR_PROMPT = """You are a research assistant. Gather facts to address the assigned sub-task. You may call the search_knowledge_base function if you need specific data. Once you have enough information, provide a concise summary."""

def execute_sub_task(sub_task: str) -> str:
    messages = [
        {"role": "system", "content": EXECUTOR_PROMPT},
        {"role": "user", "content": sub_task},
    ]
    
    while True:
        response = client.chat.completions.create(
            model="llama-3.3-70b",
            messages=messages,
            tools=[TOOL_SCHEMA],
            tool_choice="auto",
        )
        message = response.choices[0].message
        
        if message.tool_calls:
            messages.append({
                "role": "assistant",
                "content": message.content or "",
                "tool_calls": [tc.model_dump() for tc in message.tool_calls],
            })
            for tc in message.tool_calls:
                if tc.function.name == "search_knowledge_base":
                    args = json.loads(tc.function.arguments)
                    result = search_knowledge_base(args["query"])
                    messages.append({
                        "role": "tool",
                        "tool_call_id": tc.id,
                        "content": result,
                    })
        else:
            return message.content

findings = [execute_sub_task(t) for t in sub_tasks]
for i, finding in enumerate(findings, 1):
    print(f"Finding {i}:\n{finding}\n")

Step 5: Synthesize the final report

With all findings collected, I send them to a synthesis model along with a strict system prompt that enforces structure and citations. Kimi K2.6 is strong at reasoning over long context, so I use it for the final report.

The system prompt:

SYSTEM_PROMPT = """You are a senior analyst writing a structured due-diligence report. 

Rules:
- Use markdown headers.
- Cite which sub-task each fact came from.
- Include a final verdict section with a clear recommendation.
- Be concise. No filler."""

The synthesis function:

def synthesize_report(question: str, tasks: list[str], findings: list[str]) -> str:
    context = "\n\n".join(
        f"Sub-task: {t}\nFinding: {f}" for t, f in zip(tasks, findings)
    )
    user_message = f"Research Question: {question}\n\n{context}"
    
    response = client.chat.completions.create(
        model="kimi-k2.6",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
        temperature=0.3,
    )
    return response.choices[0].message.content

report = synthesize_report(RESEARCH_QUESTION, sub_tasks, findings)
print(report)

Run it

I save the complete script as research_agent.py and execute it.

python research_agent.py

Example output:

Planned tasks: [
    'Compare energy density of lithium-ion vs solid-state for aviation applications',
    'Assess safety profiles and certification implications for aviation',
    'Evaluate current manufacturing scalability and cost trajectories'
]

Finding 1:
Lithium-ion pack-level energy density is 150-180 Wh/kg, while solid-state projections reach 350-400 Wh/kg by 2030. This gives solid-state a significant advantage for weight-sensitive aviation.

Finding 2:
Solid-state batteries eliminate flammable liquid electrolytes, reducing fire risk and thermal management complexity compared to lithium-ion, which requires redundant containment.

Finding 3:
Lithium-ion benefits from existing gigafactory infrastructure. Solid-state remains pilot-scale with yield bottlenecks in ceramic electrolyte processing.

## Report: Battery Technology for Electric Aviation

### Energy Density
Solid-state batteries offer roughly double the pack-level energy density of current lithium-ion systems. This directly impacts aircraft range and payload.

### Safety
Solid-state chemistry removes thermal runaway risks inherent in liquid electrolytes. Aviation regulators view this as a potential path to simplified certification.

### Manufacturing Scalability
Lithium-ion wins near-term scalability. Solid-state manufacturing is not yet mature enough for commercial aviation volumes.

### Verdict
For programs launching before 2030, lithium-ion is the only viable choice. For next-generation platforms entering service after 2035, solid-state should be pursued aggressively, assuming manufacturing yield issues are resolved.

Wrap-up

Replace the mock knowledge base with a real search API such as Serper or Exa and add a browse_web tool to pull live data. Parallelize the sub-task execution with asyncio so the agent scales to larger research plans without linear latency growth.

Top comments (0)