Agent Architecture
Build a reusable UVM agent that cleanly separates protocol control, observation, configuration, and system-level connections.
Learning objectives
- Explain the architectural responsibility of a UVM agent.
- Build an agent containing a monitor and optional sequencer/driver pair.
- Use active and passive modes without changing the agent's external interface.
- Configure an agent with a virtual interface and active/passive mode.
- Connect the driver to the sequencer inside the agent and connect observations outside the agent.
- Recognize the boundary between reusable protocol logic and environment-level verification logic.
Step 1: What is an agent?
A UVM agent is a reusable container for the components that interact with one protocol interface. Instead of making the environment manage a driver, sequencer, and monitor individually, the agent groups them behind one architectural boundary.
For an active agent, the typical structure is:
bus_agent
├── sequencer
├── driver
└── monitor
For a passive agent:
bus_agent
└── monitor
Step 2: Understand the agent's contract
A well-designed agent should have a small, predictable public interface. The environment should not need to know how the driver implements a handshake or how the monitor detects transaction boundaries.
| Agent element | Purpose | Visible to the environment? |
|---|---|---|
| Sequencer | Accepts sequences and supplies items to the driver | Yes, when active |
| Driver | Converts transactions into protocol activity | Usually no |
| Monitor | Observes the interface and publishes transactions | Its analysis port is |
| Virtual interface | Connects class-based UVM code to HDL signals | Configuration detail |
| Active/passive mode | Controls whether stimulus-generation components exist | Configuration |
Notice the distinction: the environment may need access to the agent's sequencer to start a sequence and the monitor's analysis port to receive observations, but it should not need to reach inside the driver and manipulate protocol signals.
Step 3: Start with the configuration
Earlier lessons introduced configuration objects and the UVM configuration database. An agent can reuse that pattern to receive everything it needs to construct itself.
class bus_agent_cfg extends uvm_object;
`uvm_object_utils(bus_agent_cfg)
virtual bus_if vif;
uvm_active_passive_enum is_active = UVM_ACTIVE;
function new(string name = "bus_agent_cfg");
super.new(name);
endfunction
endclass
The configuration describes the agent rather than the testbench hierarchy. The most important values here are the interface handle and whether the agent should be active or passive.
Step 4: Build the agent
The monitor exists in both active and passive modes because observation is useful in either case. The sequencer and driver are created only when the agent is active.
class bus_agent extends uvm_agent;
`uvm_component_utils(bus_agent)
bus_sequencer sequencer;
bus_driver driver;
bus_monitor monitor;
virtual bus_if vif;
uvm_active_passive_enum is_active;
function new(string name = "bus_agent",
uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
bus_agent_cfg cfg;
super.build_phase(phase);
if (!uvm_config_db#(bus_agent_cfg)::get(
this, "", "cfg", cfg
)) begin
`uvm_fatal("NO_CFG",
"bus_agent_cfg was not found")
end
vif = cfg.vif;
is_active = cfg.is_active;
monitor = bus_monitor::type_id::create(
"monitor", this);
uvm_config_db#(virtual bus_if)::set(
this, "monitor", "vif", vif
);
if (is_active == UVM_ACTIVE) begin
sequencer = bus_sequencer::type_id::create(
"sequencer", this);
driver = bus_driver::type_id::create(
"driver", this);
uvm_config_db#(virtual bus_if)::set(
this, "driver", "vif", vif
);
end
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
if (is_active == UVM_ACTIVE) begin
sequencer.seq_item_export.connect(
driver.seq_item_port
);
end
endfunction
endclass
There are several important architectural decisions in this example.
- The monitor is always created.
- The sequencer and driver exist only in active mode.
- The virtual interface is passed to the protocol components through configuration.
- The sequencer-to-driver connection is made inside the agent.
- The agent does not know about the scoreboard.
Step 5: Why the driver-sequencer connection belongs inside the agent
The driver and sequencer are both implementation details of the agent's stimulus path. They work together as one protocol-driving mechanism.
Sequence
|
v
Sequencer
|
| seq_item_export
|
v
Driver
|
v
bus_if
|
v
DUT
The environment should not have to know which port belongs to which driver or how the sequence item handshake is implemented. The agent can hide that wiring.
This creates a useful boundary:
bus_agent
+---------------------------+
| sequencer -> driver |
| | |
| bus_if |
| |
| monitor -> analysis_port |
+---------------------------+
|
v
Environment
Step 6: Connect observations outside the agent
The monitor publishes transactions, but the agent should not decide what those transactions mean to the verification environment.
For example, the environment might connect one monitor to both a scoreboard and a coverage collector:
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
agent.monitor.analysis_port.connect(
scoreboard.analysis_imp
);
agent.monitor.analysis_port.connect(
coverage.analysis_export
);
endfunction
This separation makes the agent reusable. The same bus agent can be placed in a smoke test, a subsystem environment, or a larger system-level testbench without embedding knowledge of those consumers.
Inside the agent: connect components that implement the protocol.
Outside the agent: connect components that verify the system behavior.
Step 7: Active versus passive architecture
The same agent can often be reused in two different roles.
| Mode | Sequencer | Driver | Monitor | Typical use |
|---|---|---|---|---|
| Active | Yes | Yes | Yes | Generate and observe traffic |
| Passive | No | No | Yes | Observe traffic generated elsewhere |
Imagine a subsystem with two bus interfaces:
+-------------------+
active agent | |
--------------> DUT |
| |
passive agent <-------------- |
+-------------------+
active:
sequencer + driver + monitor
passive:
monitor only
The active agent can generate stimulus on one interface while the passive agent watches another interface. Both use the same monitor architecture.
Step 8: Keep the agent independent from the scoreboard
A common beginner mistake is to make an agent directly create or call a scoreboard. That couples protocol implementation to a particular checking strategy.
Prefer this architecture:
Environment
+-----------------------------+
| |
| +---------+ |
| | Agent | |
| | | |
| | Monitor +----+ |
| +---------+ | |
| v |
| Scoreboard |
| |
| Coverage |
+-----------------------------+
The agent says: "Here are the transactions I observed."
The scoreboard says: "Here is whether those observations are correct."
Keeping those responsibilities separate makes both components easier to reuse and debug.
Step 9: Understand the complete agent data flow
Put the pieces together:
TEST
|
| starts sequence
v
SEQUENCER
|
| sequence items
v
DRIVER
|
| protocol signals
v
DUT
|
| interface activity
v
MONITOR
|
| transactions
v
ANALYSIS PORT
/ \
v v
SCOREBOARD COVERAGE
The left side generates stimulus. The right side observes and analyzes behavior. The agent packages the reusable protocol-specific pieces without taking ownership of the entire verification strategy.
Step 10: Configure the agent from the environment
The environment can create a configuration object and place it in the configuration database before the agent is built.
bus_agent_cfg agent_cfg;
agent_cfg = bus_agent_cfg::type_id::create("agent_cfg");
agent_cfg.vif = bus_vif;
agent_cfg.is_active = UVM_ACTIVE;
uvm_config_db#(bus_agent_cfg)::set(
this,
"agent",
"cfg",
agent_cfg
);
The same environment could configure another instance as passive:
agent_cfg.is_active = UVM_PASSIVE;
The important point is that the agent implementation does not change. Configuration selects how the reusable component is assembled.
Step 11: Common architecture mistakes
| Mistake | Why it causes problems | Better approach |
|---|---|---|
| Creating a driver in passive mode | Passive monitoring should not drive the interface | Create driver/sequencer only for active agents |
| Connecting scoreboard inside agent | Couples protocol code to a checking implementation | Connect monitor analysis ports in the environment |
| Driving DUT signals from the agent itself | Blurs the driver/agent responsibility boundary | Let the driver implement protocol pin activity |
| Duplicating active and passive agent classes | Creates unnecessary maintenance and inconsistent behavior | Use one agent with active/passive configuration |
| Making the environment reach deeply into the driver | Creates tight coupling to implementation details | Expose stable interfaces such as the sequencer and monitor analysis port |
| Forgetting the monitor in passive mode | No observations are available for checking or coverage | Keep the monitor in both modes |
Step 12: Debug the agent systematically
When an agent does not behave correctly, verify its architecture before debugging the DUT.
- Check configuration: Did the agent receive its configuration object?
- Check mode: Is the agent active or passive as intended?
- Check topology: Does the active agent contain a sequencer and driver?
- Check interface: Did the driver and monitor receive the correct virtual interface?
- Check internal connection: Is the sequencer connected to the driver?
- Check observation: Is the monitor publishing transactions?
- Check external connections: Is the analysis port connected to the expected consumers?
Configuration
|
v
Agent mode
|
v
Topology
|
v
Sequencer <--> Driver
|
v
Virtual interface
|
v
Monitor
|
v
Analysis connections
Try it yourself
Build a reusable bus_agent for a simple valid/ready interface.
- Create
bus_agent_cfgcontaining a virtual interface and active/passive mode. - Create the monitor in all modes.
- Create the sequencer and driver only in active mode.
- Connect the sequencer to the driver inside the agent.
- Configure one agent as
UVM_ACTIVE. - Configure a second instance as
UVM_PASSIVE. - Connect both monitors to a scoreboard or subscriber from the environment.
- Print the topology and verify that the active agent contains three protocol components while the passive agent contains only its monitor.
bus_agent class when switching
from active to passive mode. Change only its configuration.
Key takeaways
- A UVM agent packages reusable components for one protocol interface.
- An active agent contains a sequencer, driver, and monitor.
- A passive agent contains the monitor only.
- The driver-sequencer connection belongs inside the agent because both implement the stimulus path.
- The monitor's analysis connections normally belong in the environment because consumers are verification-specific.
- Configuration lets the same agent operate in different environments without changing its implementation.
- A good agent hides protocol implementation details while exposing a small, useful verification interface.
Core mental model
Think of an agent as a reusable protocol boundary.
REUSABLE AGENT
+-----------------------+
| |
| Sequence |
| | |
| Sequencer |
| | |
| Driver -----> DUT |
| |
| Monitor |
| | |
+------|----------------+
|
v
Environment-level
checking/coverage
The agent owns how to interact with the interface. The environment owns what the observed behavior means for verification.
Once this boundary is clear, larger UVM environments become much easier to assemble: instantiate agents, configure their roles, connect their observations, and let tests control scenarios through the appropriate sequencers.
Agent = reusable protocol interaction.
Environment = system-level verification composition.
What comes next?
In the next lesson, you will assemble the pieces above into a UVM environment architecture. You will see how multiple agents, scoreboards, reference models, and coverage components fit together as one verification system.