Skip to main content

3.1 From a model to an agent

What an agent is, how it uses tools, and where agents fail.

3.1.1 Overview

In the previous chapters we saw that with LLMs we can automate many research workflows. At first glance this is pretty amazing, mindblowing in fact. But is this enough?

The limitation with LLMs is that while they can provide responses (ie. "think") they cannot "act". For example you can ask an LLM "What are common tumor suppressing proteins in humans?". The LLM will use its internal knowledge and provide an answer.

But it can't take any actions beyond that. For example if you ask "Can you provide literature publications to support your answer?" it can't go to Google Scholar and find papers for you.

This is where AI agents come into play. Agents are autonomous systems which are simply LLMs integrated with external tools. Tools are added functionalities such as a calculator, web-surfing, etc.

Tip: Agents = LLM + Tools

USER GOAL / INPUTWhat are the main proteinstructures in photosynthesis?Provide a summary.AI AGENT (LLM "BRAIN")Processes instructions,makes decisions, plans actionsand generates queries.FINAL RESPONSE TO USERSummary: Photosystem IIstarts electron transfer,then Photosystem I andCytochrome b6f, endingwith ATP synthase.TOOL INPUT: DATABASE QUERYquery: "protein structuresphotosynthesis"External tool:protein database APITOOL OUTPUT: RAW DATAPhotosystem II (PDB 3JB9),Cytochrome b6f, ATP synthase,structure data (JSON)4. SYNTHESIZES1. GENERATES TOOL INPUT2. EXECUTES TOOL3. FEEDS BACK DATA
Figure 3.1.1: The Anatomy of an LLM Agent. The LLM works here as the main "decision maker". Invoking the tools enables the LLM to have improved/specialized skills.

Here are some example use cases of AI agents in science

  • Searching the literature - see lesson 2.1 for an example implementation
  • Automating data analysis
  • Generating hypotheses
  • Evaluating models/agents
  • Writing technical reports

3.1.2 Definitions based on RL formulation

In more detail, the modern idea of AI agents connects closely with reinforcement learning (RL). In accepted modern practice RL provides the mathematical formulation to the AI agents that we will be using.

Agents: In simplest terms an AI Agent is an LLM with externally incorporated tools. But by definition, an agent is an entity that interacts with an environment, perceives states, chooses actions, and receives rewards. This flow can be described with a Markov Decision Process (MDP). This also means that the current state of an agent only depends on the state before that.

In other words, a single cell can be thought of as an agent: it senses chemical signals (current state), decides to move or release signals (action), and this all happens in its environment. That's basically an agent acting in an environment!

There are different "types" of AI agents, eg: Simple Agents, ReAct Agent. Read more here.

Environments: The agent observes or senses the environment - like how a biologist might observe cell behavior under a microscope. The environment is everything outside the agent that it can interact with. This could be:

  • A virtual environment (like a game world or a simulation)
  • The real world (a robot moving around a lab)
  • A dataset or a web API

States and tools

States: The state is a snapshot of the agent's current situation. ie. what the agent knows. It includes everything relevant to making a decision. For a cell agent, this might be the concentration of nutrients nearby. For a software agent, it might be data it has gathered. You can think of the state as the agent's memory or current understanding of the environment.

Tools: An agent uses tools to improve its performance. Think of tools as resources or specialized skills the agent can call on. For example, an AI agent answering biology questions might use a database of research papers as a tool. A robot might have a microscope or a pipette as a physical tool. In software, tools might be APIs, calculators, or data analysis modules.

3.1.3 Let's recap

Key Concepts to Remember

  • Agent - An AI that can use tools, not just answer questions
  • Tool - A Python function the AI can choose to call
  • Tool schema - The "label" on the tool so the AI knows what it does
  • Agent loop - The cycle of: think → call tool → observe → think again
  • stop_reason - How the AI tells us: "I need a tool" vs "I'm done"

3.1.4 Agents for scientific discovery

Research groups are building AI agents designed to automate many of the critical steps on the path toward scientific progress, specialized for tasks including information retrieval, information synthesis, chemical synthesis design, and data analysis.

PaperQA2 is a scientific information retrieval system (introduced in chapter 2). Finch is an agent framework designed to perform complex scientific data analysis tasks by iteratively working through Jupyter notebooks: it takes in datasets and prompts, then systematically explores, analyzes, and interprets the data. Robin is a multi-agent system for scientific discovery, applied to identify ripasudil, a Rho-kinase (ROCK) inhibitor clinically used to treat glaucoma, as a novel therapeutic candidate for dry age-related macular degeneration (dAMD), a leading cause of irreversible blindness worldwide.

Its successor, Kosmos, is described as an AI scientist. The core innovation in Kosmos is the use of structured world models, which allow efficient incorporation of information extracted over hundreds of agent trajectories. This also allows the agent to maintain coherence towards a specific research objective over tens of millions of tokens.

3.1.5 Limitations of AI Agents

AI agents are comparatively better at performing domain specific tasks than LLMs by themselves. However, this does not mean they are free of limitations. Let's take a look at some limitations AI agents face.

  • Context window constraints: LLMs have a finite context window. In multi-step agentic workflows, the accumulated message history - including tool calls, observations, and reasoning - can quickly approach or exceed this limit. When truncation occurs, the agent loses access to earlier reasoning, which can cause it to repeat steps, contradict itself, or fail entirely.
  • No memory across runs: By default, agents have no memory between runs. Each new rollout starts from scratch; once a rollout ends, nothing persists. If we wanted the agent to learn from prior protein analyses, we'd need to add external memory (e.g., a vector store or a structured cache).
  • Hallucination and unreliable tool outputs: LLMs can generate plausible-sounding but factually incorrect content, especially when answering questions outside their training data or when tool outputs are ambiguous. Catching tool exceptions and converting them to messages rather than crashing is safe, but the agent may not recover gracefully. It might keep retrying a broken tool or hallucinate a result.
  • Error propagation across steps: Agents take sequential actions, so an early mistake - a wrong tool choice, a misinterpreted observation, or a malformed argument - can cascade through subsequent steps and compound into a larger failure. Errors are not always recoverable, especially if the agent lacks explicit error-handling logic.
  • Incomplete or premature termination: Agents driven by a fixed step budget may terminate before completing a task, or may call a termination tool too early because the LLM misjudges task completion. Conversely, without a step limit, agents can loop indefinitely on unsolvable tasks.
  • Limited generalization across tasks: Agents are sensitive to how tools are described and how prompts are framed. A system prompt or tool description that works well for one task may perform poorly on a slightly different one. Agents often lack the robustness to handle out-of-distribution inputs gracefully.

Mitigations & Performance Improvements

  • Context overflow - Summarize or compress old messages; use sliding window memory; set output length limits on tool responses
  • No persistent memory - Add a vector store or structured cache to persist and retrieve results across runs
  • Hallucination - Ground LLM outputs with retrieval (RAG); require citations; use tool outputs as the source of truth over model priors
  • Error propagation - Add explicit error handling and retry logic; validate tool inputs/outputs before passing them downstream
  • Premature/no termination - Check for termination signals after every step; set sensible step budgets based on task complexity
  • Poor generalization - Invest in prompt engineering and tool description clarity; test on diverse inputs; use few-shot examples in the system prompt

Evaluating agent performance

This is as important as building the agent itself. Rather than just inspecting final outputs, consider:

Frameworks like LDP and Aviary are designed with evaluation in mind: trajectories are structured objects you can analyze programmatically, making it straightforward to build automated eval pipelines on top of your existing rollout infrastructure.

  • Trajectory analysis: did the agent take the most efficient path, or did it waste steps?
  • Tool use accuracy: did it call the right tools with valid arguments?
  • Failure mode logging: track when and why agents fail to complete tasks, to guide future improvements

Further reading

Original reference materials. External notebooks run on their own services, not on this site.