Graph engineering is the newest way of building with AI: instead of asking one chatbot one question, you design a map of small AI workers, tools and checkpoints that hand work to each other until a job is done. It is the latest step in a short but fast journey that started with prompt engineering in 2022. This guide explains each step in plain language, with simple diagrams and trading and investing examples, so you can follow the conversation even if you have never written a line of code.
Key takeaways
- AI building has moved through seven stages: prompt, context, agentic, spec, harness, loop and graph engineering. Each stage solved a problem the previous one could not.
- The context window, the amount of text an AI can read at once, grew from about 2,000 tokens in 2020 to around 1 million tokens by 2024. That growth made the later stages possible.
- An agent is an AI model that can use tools and work in steps. A harness is the safe workshop around it: tools, memory, permissions, checks, budget limits and logs.
- Graph engineering connects many agents and checks into a map: an orchestrator splits the work, subagents work in parallel, a verifier checks the result and a human approves.
- For traders, the practical rule stays simple: let AI research, code and summarise, but keep a human approval step before any real money moves.
From prompt engineering to graph engineering: the big picture

Think of how a trading desk grows. First, one analyst answers questions. Then you give the analyst better files. Then you let the analyst use a terminal. Then you write a clear brief before work starts, set up a proper office with rules, ask the analyst to check and redo work, and finally hire a team with a desk head who splits the work. AI building went through the same steps.
| Stage | In one line | Trading example |
|---|---|---|
| Prompt engineering | Ask a better question | “Explain the RSI indicator in simple words with a Nifty example” |
| Context engineering | Give the AI the right information | Paste your trade journal and ask why your losing trades lose |
| Agentic engineering | Let the AI use tools | AI fetches Nifty data, runs a backtest and shows the result |
| Spec engineering | Write the plan before the work | A one-page brief: strategy rules, data period, costs, what “good” means |
| Harness engineering | Build a safe workshop around the AI | Read-only market data, no order placement without your approval |
| Loop engineering | Let the AI try, check and retry | Backtest fails, AI reads the error, fixes the code, runs again |
| Graph engineering | Many agents and checks on one map | Price, news, results and options agents feed one verified report |
1. Prompt engineering: asking better questions
When ChatGPT arrived in late 2022, the skill everyone talked about was prompt engineering: how you phrase the question. “Tell me about Nifty” gives a vague answer. “You are a technical analyst. Explain the last 3 months of Nifty in 5 bullet points for a beginner, and list two levels to watch” gives a useful one. The model is the same; the instruction is better. Our guide on how experienced traders should prompt Claude to build strategies covers this stage in detail.
The limit: a perfect question cannot fix missing information. If the AI has not seen your trade history, no wording will make it understand your trades.
2. Context engineering: giving the right information
In mid-2025 the AI community started using the term context engineering, popularised by Andrej Karpathy, to describe the real skill: filling the AI’s working memory with exactly what it needs for the task. That means the right documents, data, examples, rules and past conversation, and leaving out noise.
A simple investing example: instead of asking “Is this mutual fund good?”, you give the AI the fund’s factsheet, its 5-year returns against the benchmark, the expense ratio and your goal (retirement in 15 years). The answer improves because the context improved.
How the context window expanded

The context window is how much text an AI can read and keep in mind at one time. It is measured in tokens; one token is roughly three quarters of a word. Early models could hold only a few pages. Today’s models can hold entire books, annual reports or code repositories.
| Year | Typical upper limit | Roughly equal to |
|---|---|---|
| 2020 (GPT-3) | about 2,000 tokens | 3 to 4 pages |
| 2022 (early ChatGPT) | about 4,000 tokens | 6 to 8 pages |
| 2023 (GPT-4 32K) | 32,000 tokens | a long research report |
| Late 2023 (Claude 2.1) | 200,000 tokens | a 500-page book |
| 2024 (Gemini 1.5 Pro) | 1,000,000 tokens | several annual reports or a full codebase |
A bigger window does not mean you should dump everything into it. Models still pay most attention to what is relevant and well organised, which is why context engineering, choosing what goes in, still matters. For a trader, that might mean giving the AI only the last 2 years of daily data and your strategy rules, not 20 years of tick data.
3. Agentic engineering: letting AI use tools
A chatbot only talks. An agent is an AI model that can also act: it can call tools, read the results and decide what to do next. These tools are called agentic tools.
What are agentic tools?
Agentic tools are the hands of an AI agent. Common examples:
- Web search to read today’s news or an RBI circular.
- Data tools to fetch stock prices, option chains or mutual fund NAVs.
- Code runner to run a Python backtest or calculate returns.
- File tools to read a PDF annual report or write a spreadsheet.
- Broker or trading platform APIs to read positions or, with permission, place orders. A standard called MCP (Model Context Protocol) lets AI assistants connect to such tools in a common way.
What is the role of an agent?
The agent’s job is to turn a goal into steps and carry them out. Ask “Compare HDFC Bank and ICICI Bank on the last four quarterly results”, and an agent will search for the results, read them, pull the numbers into a table, calculate growth and write the summary. A chatbot would answer from memory and could be out of date. If you want to see a working example, our NSE MCP Python tutorial builds a simple stock market AI agent.
What can an AI agent do? Its core capabilities
Think of an agent as a junior analyst sitting at a desk with a computer. What makes it an agent and not a chatbot is a set of capabilities that work together:
| Capability | What it means | Trading example |
|---|---|---|
| Understand the goal | Reads your request and works out what “done” looks like | “Find Nifty 50 stocks near their 52-week high with rising volume” |
| Plan | Breaks the goal into ordered steps | Get the stock list, fetch prices, compute highs, filter, rank |
| Use tools | Calls search, data feeds, code runners, files and APIs | Fetches daily candles through a market data API |
| Observe | Reads what each tool returned, including errors | Notices 3 symbols returned no data |
| Remember | Keeps notes during the task and, with a harness, across sessions | Remembers you prefer NSE symbols and Indian date formats |
| Self-check | Tests its own output against the goal | Cross-checks one stock’s 52-week high by hand |
| Ask for help | Stops and asks a human when unsure or when permission is needed | “Should I place this order?” |
| Delegate | Hands parts of the job to subagents | Sends sector research to five separate helper agents |
The first six capabilities make one agent useful. The last one, delegation, is where graph engineering begins.
4. Spec engineering: writing the plan first
Agents are fast, and fast plus vague equals fast mistakes. Spec engineering, also called spec-driven development, means writing a clear specification before the agent starts: what to build, what the inputs are, what rules to follow and how you will know it is correct.
Trading example of a short spec for an agent building a backtest:
- Strategy: buy Nifty when the 20-day moving average crosses above the 50-day, exit on the reverse cross.
- Data: daily Nifty 50 closes, January 2015 to December 2025.
- Costs: include 0.05% per trade for brokerage and slippage.
- Output: total return, maximum drawdown, number of trades and an equity curve chart.
- Done means: results match a manual check on three sample trades.
With that page, the agent has far less room to guess. The spec becomes the contract that later checks are measured against.
5. Harness engineering: building the safe workshop

In 2026, people building AI agents settled on a simple formula: Agent = Model + Harness. The model is the brain. The harness is everything around it that makes the brain useful and safe. Software developer Mitchell Hashimoto described the idea as engineering the setup so that the agent never makes the same mistake again.
A harness typically includes:
- Tools: which tools the agent may use.
- Memory: notes and instructions it keeps between sessions.
- Permissions: what it can and cannot touch, and when it must ask a human.
- Checks: tests, linters and validations that run while it works.
- Budget limits: caps on time, tokens or money spent.
- Logs: a record of every step, so you can audit what it did.
For a trader, a good harness might say: the agent may read market data and write code freely, may run backtests, but may never place a live order without your approval, and must stop if it spends more than a set amount on API calls. The harness matters as much as the model. One reported example: a coding agent moved from 30th to 5th place on a benchmark by changing only its harness, not the model.
6. Loop engineering: try, check, retry

Real work rarely succeeds on the first attempt. Loop engineering designs how an agent repeats a cycle until the job is done:
- Think: plan the next step.
- Act: use a tool.
- Observe: read the result.
- Check: is it done, or should it try again?
This cycle is called the agentic loop. A chatbot answers once and stops. An agent keeps going round the loop, using each result to decide the next move, until the goal is met or a limit is hit.
The agentic loop in action: a backtest example
Say you ask: “Backtest a 20/50 moving average crossover on Nifty for the last ten years.” Here is what happens inside the loop:
| Round | Think | Act | Observe | Check |
|---|---|---|---|---|
| 1 | I need ten years of daily Nifty data | Call the data tool | Got 2,480 daily candles | Data ready, move on |
| 2 | Write the crossover backtest | Run the Python code | Script crashes on a missing date | Not done, fix it |
| 3 | Holiday gaps break the date index | Edit code to skip missing dates, run again | Backtest completes, 38 trades | Check the numbers |
| 4 | Verify a few trades by hand | Recalculate 3 sample trades | 2 match, 1 is off by one day | Not done, fix it |
| 5 | Signal uses today’s close but enters today | Shift entry to the next day’s open, run again | All 3 samples match | Done, write the report |
Notice round 5. The agent caught a classic look-ahead bias, the kind of mistake that makes a backtest look better than reality, only because its loop included a check step. Without that step it would have stopped at round 3 with confident but wrong results.
Loop engineering is about designing this cycle well. It needs a clear “done” test (from the spec), real checks rather than the agent simply saying “looks good”, and guard rails: a maximum number of rounds and a spending cap, so it does not spin forever or keep burning tokens.
7. Graph engineering: many agents, one map

A single agent in a loop is like one very fast analyst. For bigger jobs, one analyst becomes a bottleneck and starts mixing things up. Graph engineering designs a team: a map (a graph) where each box is a unit of work and each arrow says what happens next.
Where the word “graph” comes from: Euler’s seven bridges

The idea is almost 300 years old. In 1736 the mathematician Leonhard Euler looked at a puzzle from the city of Konigsberg: two river banks and two islands, joined by seven bridges. Could you walk through the city crossing every bridge exactly once? People tried route after route and failed. Euler’s breakthrough was to ignore the streets and draw only what mattered: each piece of land became a dot (a node) and each bridge became a line (an edge). With that simple drawing he proved the walk was impossible, because every piece of land had an odd number of bridges. That drawing was the start of graph theory.
Graph engineering borrows the same trick. Ignore the details, draw the work as nodes and edges, and the structure tells you what can run together, what must wait and where things can go wrong.
A real example: deep research as a graph of agents

When you ask a modern AI coding assistant such as Claude Code for deep research on a topic, it does not have to hand the whole job to one agent. It can write a small workflow program on the fly, a runtime that turns your research plan into phases and launches a fresh team of agents for that one request. A typical research graph looks like this:
| Phase | Agents | Job |
|---|---|---|
| 1. Scope | 1 | Turn your question into sub-topics and a plan |
| 2. Find sources | 5 | One agent per sub-topic finds credible websites and reports |
| 3. Fetch facts | 25 | Read the sources and pull out facts with links |
| 4. Verify and vote | 75 | Independent checkers confirm each fact and vote on credibility |
| 5. Write report | 1 | Combine only the verified facts into the final report |
That is more than 100 agents, each with its own instructions and its own context window, and each phase runs its agents side by side. Because work only flows forward, from left to right, with no step pointing back to an earlier one, this shape is called a directed acyclic graph, or DAG. Add an arrow back, such as “if the verifier rejects a fact, fetch again”, and it becomes a graph with a loop. Every new request gets a new graph: a narrow question might need 10 agents, a broad market study might need 200.
For an investor, the same pattern could research a sector: one agent scopes the question, a few find sources on demand, regulation and competition, many agents read company filings, a large group cross-checks the numbers, and one agent writes the note.
Why use many agents instead of one?
- Time. Twenty-five agents reading at once finish far sooner than one agent reading twenty-five sources in turn.
- Focus. Each agent has its own context window for one small goal. A single agent doing everything has to keep squeezing the goal, the plan, its notes and the current task into one window and keep summarising, which is where mistakes creep in.
- Independent checking. Verifiers that did not write the facts are more likely to catch errors, just as a second analyst catches what the first one missed.
The catch: cost
More agents means more tokens. Anthropic reported in its write-up on its multi-agent research system that agents typically use about 4 times more tokens than a normal chat, and multi-agent systems about 15 times more. A rough example: 108 agents that each start with 20,000 tokens of instructions and context read about 2.2 million input tokens before doing any work. On a frontier model that is a noticeable bill for a single question. Prompt caching, where repeated instructions are stored and re-read at a fraction of the normal price, can cut that input cost sharply. So graphs are worth it for big, valuable jobs, and overkill for a quick question.
Why graph engineering, and why now?
Agents talking to agents is not new. Microsoft’s AutoGen showed it in 2023, and LangChain’s LangGraph framework has been building agent graphs since around the same time. In late 2024 Anthropic described common patterns such as chaining steps, routing, running work in parallel, orchestrator and workers, and an evaluator that critiques a generator until a condition is met. What changed, as LangChain put it in its look back at three years of graph engineering, was not the graph but what each node can do. In 2023 a node was a single model call. Today a node can be a full coding agent with tools, memory and a harness. Once each node became reliable, the bottleneck moved from “can one agent do this?” to “how should we connect many capable agents?”. That is the question graph engineering answers, and it is why the idea is coming back now.
Nodes and edges in plain words
- Nodes are the boxes: an agent, a tool, a simple calculation, a database lookup or a human approval.
- Edges are the arrows: run next, run in parallel, run only if a condition is true, or go back and retry.
How agents and subagents work in a dynamic workflow
Here is how a pre-market research workflow could run for a trader who wants a morning report on five stocks:
- Orchestrator: reads your request and splits it into separate jobs.
- Subagents in parallel: a price agent pulls charts and levels, a news agent reads overnight news, a results agent checks the latest quarterly numbers, and an options agent reads open interest and implied volatility. Each has a small, focused context, so it does not get confused.
- Verifier: an independent agent checks the facts and flags anything unsupported, for example a price that does not match the data source.
- Human approval: you read the draft and decide.
- Final report: a clean one-page summary.
Two things make this “dynamic”. First, the orchestrator decides at run time how many subagents to start: five stocks means five research tracks, fifty stocks means fifty, and they run side by side. Second, the arrows can branch: if the verifier finds a problem, the work goes back to the right subagent instead of the whole job starting again. Known business rules, such as “never trade if the daily loss limit is hit”, stay as fixed code on the map, not as a request inside a prompt.
We use this pattern ourselves. To clean up and improve thousands of articles on this site, we ran a graph of AI workers: dozens of agents each handled a batch of posts in parallel, a separate checker verified every batch, and nothing was published until it passed review. One agent could not have held 4,000 articles in mind; a graph of agents with checks could.
Prompt vs context vs harness vs graph engineering: quick comparison
| Prompt | Context | Harness | Graph | |
|---|---|---|---|---|
| Main question | How do I ask? | What should the AI know? | What can the AI do safely? | How do many agents work together? |
| Who does the work | One model, one reply | One model, better inputs | One agent with tools and rules | A team of agents and checks |
| Best for | Explanations, quick drafts | Analysis of your own data | Coding, research, automation | Large, multi-step jobs |
| Main risk | Vague answers | Missing or noisy information | Unsafe actions | Complexity and cost |
What this means for traders and investors
- Start simple. Good prompts and good context solve most everyday needs: explaining concepts, summarising results, reviewing your journal.
- Use agents for repeatable research. Daily screeners, results summaries and backtests are natural fits.
- Insist on a harness. Read-only data by default, sandbox or paper trading first, spending limits and logs. Platforms such as OpenAlgo offer a sandbox mode for exactly this.
- Keep a human in the loop for money. Let the graph prepare the trade; you press the button.
- Check the numbers. AI can still be wrong. A verifier step and your own spot checks are part of the system, not optional extras. Our guide to LLM metrics and benchmarks explains how to judge which model to trust for which job.
If you want to go one step further and build your own, the LLM trading agent tutorial in Python walks through a single agent, which is the building block of every graph.
Frequently Asked Questions
What is graph engineering in AI?
Graph engineering is the design of an AI system as a map of connected steps. Each step can be an agent, a tool, a fixed rule or a human approval, and the connections decide what runs next, what runs in parallel and when work goes back for a retry.
What is the difference between prompt engineering and context engineering?
Prompt engineering improves the question. Context engineering improves the information the AI sees while answering, such as documents, data, examples and rules. Better context usually beats a cleverer prompt.
What is harness engineering?
Harness engineering is building the environment around an AI model so it works reliably: the tools it may use, memory, permissions, automatic checks, budget limits and logs. The common summary is Agent = Model + Harness.
What are agentic tools?
Agentic tools are the actions an AI agent can take, such as web search, fetching market data, running code, reading files or calling a broker API. They let the AI do work instead of only talking about it.
Can AI agents trade on their own?
Technically yes, through broker APIs, but it is risky. A sensible setup lets agents research, backtest and prepare orders, runs them in sandbox mode first, and keeps a human approval step before any live order.
Learn by watching: free videos every week
Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

