Dynamiq
Get Started

Quickstart

Run an LLM workflow in about 20 lines of Python, then build a ReAct agent that answers questions with a web-search tool.

This page takes you from pip install to a working agent in two short programs. You need Python 3.10+, the dynamiq package installed, and an OPENAI_API_KEY in your environment (any supported provider works the same way).

1. An LLM workflow

A Workflow wraps a Flow — the DAG of nodes — and gives you one run() call for the whole graph. Here the graph is a single OpenAI LLM node with a Jinja-templated prompt:

from dynamiq import Workflow
from dynamiq.connections import OpenAI as OpenAIConnection
from dynamiq.nodes.llms import OpenAI
from dynamiq.prompts import Prompt, Message

llm = OpenAI(
    id="translator",
    connection=OpenAIConnection(),  # reads OPENAI_API_KEY from the environment
    model="gpt-4o-mini",
    temperature=0.3,
    max_tokens=1000,
    prompt=Prompt(messages=[
        Message(role="user", content="Translate the following text into English: {{ text }}"),
    ]),
)

workflow = Workflow()
workflow.flow.add_nodes(llm)

result = workflow.run(input_data={"text": "Hola Mundo!"})
print(result.status)                                # RunnableStatus.SUCCESS
print(result.output["translator"]["output"]["content"])  # "Hello World!"

Three things to notice:

  • The workflow's input_data keys feed the prompt template — {{ text }} is rendered with "Hola Mundo!".
  • result.output is keyed by node id; each entry holds that node's status, input, and output. The LLM node's text lives at output["content"].
  • You could also call llm.run(input_data={...}) directly without a workflow — every node is independently runnable. Workflows earn their keep once you have more than one node; see Workflows, Flows & Nodes.

2. An agent with a tool

The Agent node is a ReAct agent: it reasons in a loop, decides when to call its tools, and stops when it has an answer. Give it an LLM, a role, and a Tavily web-search tool (set TAVILY_API_KEY in your environment, or swap in any other tool node):

from dynamiq.connections import OpenAI as OpenAIConnection, Tavily as TavilyConnection
from dynamiq.nodes.agents import Agent
from dynamiq.nodes.llms import OpenAI
from dynamiq.nodes.tools.tavily import TavilyTool

llm = OpenAI(
    connection=OpenAIConnection(),
    model="gpt-4o-mini",
    temperature=0.1,
)

search_tool = TavilyTool(connection=TavilyConnection())  # reads TAVILY_API_KEY

agent = Agent(
    name="research-agent",
    llm=llm,
    tools=[search_tool],
    role="Research assistant that answers questions with up-to-date sources.",
    max_loops=10,
)

result = agent.run(
    input_data={"input": "What were the key announcements at the latest OpenAI DevDay?"}
)
print(result.output["content"])

Agents take their task under the input key and return the final answer at result.output["content"]. max_loops caps the reason–act cycle so a confused agent can't run forever.

3. Run it async

run() detects whether it's called from an async context and dispatches accordingly, so the same agent drops into an asyncio app unchanged:

import asyncio

async def main():
    result = await agent.run(
        input_data={"input": "Summarize this week's AI funding news."}
    )
    print(result.output["content"])

asyncio.run(main())

See Running workflows & results for run_sync/run_async, statuses, and cancellation.

Where to go next

On this page