LLMs

Build an intelligent agent system for market analysis with DeepSeek

Build a market analysis agent system on DeepSeek models: a research agent with search and code, a validation agent, and a manager that coordinates them.

Oleksii BabychMachine learning engineer4 min readUpdated

In short

This tutorial builds a market analysis system on DeepSeek models with the open-source Dynamiq SDK: a research agent with web search and a code sandbox, a validation agent that checks the findings, and a manager agent that coordinates them. It also covers when DeepSeek's models fit, and how regulated teams run open weights on their own infrastructure instead of a hosted API.

To build a market analysis agent system with DeepSeek, pair a research agent that gathers data with a validation agent that checks it, and let a manager agent coordinate the two. With the Dynamiq SDK, each agent takes a few lines of Python, and DeepSeek is one of 29 model providers you can switch to by changing a single node. The example below produces a sourced market brief for an online seller.

Why use DeepSeek for agent workloads?

DeepSeek became a serious option for enterprise builders in January 2025, when it released DeepSeek-R1, a reasoning model with open weights under the MIT license. The DeepSeek-R1 paper describes how reinforcement learning taught the model to reason step by step, and the weights are published on Hugging Face.

Three properties make DeepSeek's models worth testing for agents:

  • Open weights. You can run the models in your own environment, which matters when data may not leave your perimeter.
  • Two modes of work. Its current API models support a fast non-thinking mode and a slower thinking mode, so you can match the mode to the task.
  • Price per token. Compare current prices on DeepSeek's pricing page against your volume before you decide.

Before you send business data to any hosted API, check where the provider processes and stores it, and what its terms allow. For regulated data, the safer pattern is to run open weights on infrastructure you control, which this guide covers below.

What does the market analysis system look like?

The system has three layers:

Layer Components Job
Tools Tavily web search, E2B code sandbox Fetch current data and run calculations
Agents Research agent, validation agent Gather findings; check them against sources
Orchestration Manager agent Plan, delegate, and write the brief from checked facts

The manager decides which agent to call and when, so the same system can answer a narrow pricing question or produce a full market brief. That is the adaptive orchestration pattern described in our guide to agent orchestration patterns.

Step 1: Install and configure

pip install dynamiq
export DEEPSEEK_API_KEY="..."
export TAVILY_API_KEY="..."
export E2B_API_KEY="..."

Step 2: Set up the models

Use the faster model for research and coordination and the stronger model for validation.

from dynamiq.connections import DeepSeek as DeepSeekConnection
from dynamiq.nodes.llms import DeepSeek

# Model names from DeepSeek's API documentation at the time of writing; check its current list.
fast_llm = DeepSeek(connection=DeepSeekConnection(), model="deepseek-flash")
strong_llm = DeepSeek(connection=DeepSeekConnection(), model="deepseek-v4-pro")

Step 3: Create the research and validation agents

Each agent gets a description, which the manager reads to decide when to call it.

from dynamiq.connections import E2B as E2BConnection
from dynamiq.connections import Tavily as TavilyConnection
from dynamiq.nodes.agents import Agent
from dynamiq.nodes.tools.e2b_sandbox import E2BInterpreterTool
from dynamiq.nodes.tools.tavily import TavilyTool
from dynamiq.nodes.types import Behavior, InferenceMode

search = TavilyTool(connection=TavilyConnection())
sandbox = E2BInterpreterTool(connection=E2BConnection())

research_agent = Agent(
    name="Research agent",
    description="Collects current market data from the web and runs calculations.",
    role=(
        "You research markets. Find current, sourced data with web search, use the code "
        "interpreter for any calculation, and cite a source for every figure."
    ),
    llm=fast_llm,
    tools=[search, sandbox],
    inference_mode=InferenceMode.XML,
    max_loops=10,
    behaviour_on_max_loops=Behavior.RETURN,
)

validation_agent = Agent(
    name="Validation agent",
    description="Checks research findings for unsupported claims, stale data and contradictions.",
    role=(
        "You fact-check market research. Verify each figure against its source with web search, "
        "flag anything unsupported or out of date, and return the corrected findings."
    ),
    llm=strong_llm,
    tools=[search],
    inference_mode=InferenceMode.XML,
    max_loops=8,
    behaviour_on_max_loops=Behavior.RETURN,
)

InferenceMode.XML makes the agents express tool calls in XML tags, which works with any chat model, including ones without native function calling. Behavior.RETURN makes an agent return its best answer when it reaches its loop limit, instead of raising an error.

Step 4: Add a manager and run the analysis

The manager has the two agents as its tools. It delegates research, sends the findings for validation, and writes the brief only from what survived the check.

from dynamiq import Workflow
from dynamiq.flows import Flow

manager = Agent(
    name="Market analysis manager",
    role=(
        "Coordinate a market analysis. Delegate research to the research agent, send its findings "
        "to the validation agent, and write the final brief only from validated findings. "
        "Call sub-agents with {'input': '<task>'} payloads."
    ),
    llm=fast_llm,
    tools=[research_agent, validation_agent],
    inference_mode=InferenceMode.XML,
    max_loops=12,
    behaviour_on_max_loops=Behavior.RETURN,
)

workflow = Workflow(flow=Flow(nodes=[manager]))
result = workflow.run(
    input_data={
        "input": (
            "I sell handmade ceramics on Etsy. Analyze demand, pricing and competition for the "
            "next quarter and recommend three product lines, with sources."
        )
    }
)
print(result.output[manager.id]["output"]["content"])

What does the output look like?

The brief typically covers market viability, recommended product categories with the evidence behind each, pricing guidance, the main risks and a list of sources. Because the validation agent checks each figure, unsupported numbers are flagged or removed instead of passed through.

Treat the brief as research, not as a verdict: the figures are only as current as the sources the agents found. Keep the source list, and spot-check the numbers that drive a decision.

How do you run DeepSeek models on your own infrastructure?

Serve the open weights with an inference server that exposes an OpenAI-compatible API, such as vLLM, then point the agents at it with the SDK's CustomLLM node. Nothing else in the workflow changes.

import os

from dynamiq.connections import HttpApiKey
from dynamiq.nodes.llms import CustomLLM

self_hosted_llm = CustomLLM(
    connection=HttpApiKey(url="https://llm.internal.example.com/v1", api_key=os.environ["LLM_API_KEY"]),
    model="your-deepseek-deployment",  # the model name your server exposes
    provider_prefix="openai",  # route as an OpenAI-compatible endpoint
)

On the Dynamiq platform, the AI Gateway gives agents one endpoint for the most-used hosted models, and managed inference runs open models for you; see models.

For teams that need everything inside their own cloud or data center, Dynamiq itself can be self-hosted; see where Dynamiq runs.

When should you choose DeepSeek?

DeepSeek is worth testing when:

  • You need open weights to keep data in your environment.
  • The workload is high-volume and token cost dominates.
  • Tasks benefit from explicit reasoning, such as validation or multi-step analysis.

It is a weaker fit when your organization restricts the provider or the model's origin, or when a task needs a capability you have only validated on another model. Because the agent code doesn't depend on the provider, you can run the same workflow on several models and compare the results with evaluations before you commit.

FAQ

Is DeepSeek open source?

DeepSeek publishes open weights for many of its models. DeepSeek-R1 was released in January 2025 under the MIT license, which allows commercial use and modification. Check the license of the specific model version you plan to use.

Can I use DeepSeek models with the Dynamiq SDK?

Yes. The SDK includes a DeepSeek LLM node for DeepSeek's API, and the CustomLLM node connects to any OpenAI-compatible endpoint, including a server hosting DeepSeek's open weights in your own environment.

Why use two agents instead of one?

Separating research from validation catches more mistakes. The research agent is optimized to find information quickly; the validation agent has a single job, checking each figure against its source, and can run on a stronger model.

Is it safe to send company data to DeepSeek's API?

That depends on your data and your policies. Review where the provider processes and stores data and what its terms allow. For sensitive or regulated data, run the open weights on infrastructure you control instead of calling the hosted API.

Which search tool should the research agent use?

The SDK includes several, including Tavily, Exa, Scale SERP, Firecrawl and Jina search. Tavily lets you restrict results to specific domains, which helps when only certain sources are acceptable.

Put this into practice.

See an agent built for your workflow, running in your environment, with our engineers.