Skip to content

Commit edbc966

Browse files
authored
Added integration: LlamaIndex (#7)
* added llama index integration * updated docs of agent interfaces to be more consistent across frameworks.
1 parent adc751e commit edbc966

16 files changed

Lines changed: 1337 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- [LlamaIndex](https://github.com/run-llama/llama_index) integration: `LlamaIndexAgentAdapter` and `LlamaIndexUser` for evaluating LlamaIndex workflow-based agents (PR: #7)
13+
14+
- Supports async workflow execution with proper event loop handling
15+
1216
- The `logs` property inside `SmolAgentAdapter` and `LanggraphAgentAdapter` are now properly filled. (PR: #3)
1317

1418
### Changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,23 @@ The package is published on PyPI as `maseval`. To install the stable release for
4545
pip install maseval
4646
```
4747

48-
If you want the optional integrations used by the examples (smolagents, langchain, etc.), install the examples extras:
48+
If you want the optional integrations used by the examples (smolagents, langgraph, llamaindex, etc.), install the examples extras:
4949

5050
```bash
5151
pip install "maseval[examples]"
5252
```
5353

54-
Or install only the smolagents integration:
54+
Or install specific framework integrations:
5555

5656
```bash
57+
# Smolagents
5758
pip install "maseval[smolagents]"
59+
60+
# LangGraph
61+
pip install "maseval[langgraph]"
62+
63+
# LlamaIndex
64+
pip install "maseval[llamaindex]"
5865
```
5966

6067
## Example

docs/interface/agents/langgraph.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# LangGraph
22

3-
Adapter for the LangGraph agent framework. The page renders the adapter API when
4-
the optional dependency is available in the build environment.
3+
Adapter for the `LangGraph` agent framework.
4+
5+
- [Documentation](https://langchain-ai.github.io/langgraph/)
6+
- [Code Repository](https://github.com/langchain-ai/langgraph)
7+
8+
## Installation
9+
10+
```bash
11+
pip install maseval[langgraph]
12+
```
13+
14+
Alternatively, install langgraph directly:
15+
16+
```bash
17+
pip install langgraph
18+
```
19+
20+
## API Reference
521

622
::: maseval.interface.agents.langgraph
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# LlamaIndex
2+
3+
Adapter implementing commonly used functions for `LlamaIndex`'s workflow-based agent system.
4+
5+
- [Documentation](https://docs.llamaindex.ai/)
6+
- [Code Repository](https://developers.llamaindex.ai/python/framework/)
7+
8+
## Installation
9+
10+
```bash
11+
pip install maseval[llamaindex]
12+
```
13+
14+
Alternatively, install llama-index-core directly:
15+
16+
```bash
17+
pip install llama-index-core
18+
```
19+
20+
## API Reference
21+
22+
::: maseval.interface.agents.llamaindex
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
# Huggingface `Smolagents`
1+
# SmolAgents
22

3-
Adapter implementing commonly used functions for the Huggingface
4-
[smolagents](https://huggingface.co/docs/smolagents/en/index) package. The
5-
API will be rendered when the optional dependency is installed in the build
6-
environment.
3+
Adapter implementing commonly used functions for the HuggingFace `smolagents` package.
4+
5+
- [Documentation](https://huggingface.co/docs/smolagents/en/index)
6+
- [Code Repository](https://github.com/huggingface/smolagents)
7+
8+
## Installation
9+
10+
```bash
11+
pip install maseval[smolagents]
12+
```
13+
14+
Alternatively, install smolagents directly:
15+
16+
```bash
17+
pip install smolagents
18+
```
19+
20+
## API Reference
721

822
::: maseval.interface.agents.smolagents

docs/reference/agent.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ Adapters that integrate MASEval with agent frameworks:
88

99
::: maseval.interface.agents.smolagents.SmolAgentAdapter
1010

11-
<!-- ::: maseval.interface.agents.langgraph -->
11+
::: maseval.interface.agents.langgraph.LangGraphAgentAdapter
12+
13+
::: maseval.interface.agents.llamaindex.LlamaIndexAgentAdapter

docs/reference/user.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ The User is initialized with a persona and a scenario, both of which are typical
99
Some integrations provide convenience user/tool implementations for specific agent frameworks. For example:
1010

1111
::: maseval.interface.agents.smolagents.SmolAgentUser
12+
13+
::: maseval.interface.agents.langgraph.LangGraphUser
14+
15+
::: maseval.interface.agents.llamaindex.LlamaIndexUser

maseval/interface/agents/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@
2020
__all__.extend(["LangGraphAgentAdapter", "LangGraphUser"])
2121
except ImportError:
2222
pass
23+
24+
# Conditionally import llamaindex
25+
try:
26+
from .llamaindex import LlamaIndexAgentAdapter, LlamaIndexUser # noqa: F401
27+
28+
__all__.extend(["LlamaIndexAgentAdapter", "LlamaIndexUser"])
29+
except ImportError:
30+
pass

maseval/interface/agents/langgraph.py

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,88 @@ def _check_langgraph_installed():
3232
class LangGraphAgentAdapter(AgentAdapter):
3333
"""An AgentAdapter for LangGraph CompiledGraph agents.
3434
35-
Requires langgraph to be installed.
35+
This adapter integrates LangGraph's compiled graphs with MASEval's benchmarking framework,
36+
converting LangChain/LangGraph message types to OpenAI-compatible MessageHistory format.
37+
It preserves tool calls, tool responses, multi-modal content, and supports both stateless
38+
and stateful (checkpointed) graph execution.
39+
40+
LangGraph graphs can operate in two modes:
41+
42+
- **Stateless**: Messages from invoke() result are cached in the adapter for access
43+
- **Stateful**: With checkpointer and thread_id, messages are fetched from persistent state
44+
45+
The adapter automatically handles both modes, preferring persistent state when available
46+
and falling back to cached results for stateless graphs.
47+
48+
How to use:
49+
1. **Create a LangGraph graph** with state and nodes
50+
2. **Compile the graph** (optionally with checkpointer for state persistence)
51+
3. **Wrap with LangGraphAgentAdapter** to enable MASEval integration
52+
4. **Use in benchmarks** or call directly for testing
53+
5. **Access traces and config** for analysis and debugging
54+
55+
Example workflow:
56+
```python
57+
from maseval.interface.agents.langgraph import LangGraphAgentAdapter
58+
from langgraph.graph import StateGraph, MessagesState
59+
from langgraph.checkpoint.memory import MemorySaver
60+
61+
# Define your graph
62+
def chatbot(state: MessagesState):
63+
# Your agent logic
64+
return {"messages": [response]}
65+
66+
# Build graph
67+
graph = StateGraph(MessagesState)
68+
graph.add_node("chatbot", chatbot)
69+
graph.set_entry_point("chatbot")
70+
graph.set_finish_point("chatbot")
71+
72+
# Compile (stateless)
73+
compiled_graph = graph.compile()
74+
agent_adapter = LangGraphAgentAdapter(compiled_graph, "agent_name")
75+
76+
# Or compile with checkpointer (stateful)
77+
memory = MemorySaver()
78+
compiled_graph = graph.compile(checkpointer=memory)
79+
config = {"configurable": {"thread_id": "session_1"}}
80+
agent_adapter = LangGraphAgentAdapter(
81+
compiled_graph,
82+
"agent_name",
83+
config=config
84+
)
3685
37-
This adapter converts LangChain/LangGraph message types to MASEval's
38-
OpenAI-compatible MessageHistory format. It preserves tool calls, tool
39-
responses, and multi-modal content.
86+
# Run agent
87+
result = agent_adapter.run("What's the weather?")
4088
41-
LangGraph graphs can be stateless or stateful (with checkpointer). This
42-
adapter supports both modes:
43-
- Stateless: Messages from invoke() result are cached in adapter
44-
- Stateful: Messages fetched from graph state if config/thread_id provided
89+
# Access message history in OpenAI format
90+
for msg in agent_adapter.get_messages():
91+
print(f"{msg['role']}: {msg['content']}")
4592
46-
Example:
47-
```python
48-
from maseval.interface.agents.langgraph import LangGraphAgentAdapter
49-
from langgraph.graph import StateGraph
93+
# Gather execution traces
94+
traces = agent_adapter.gather_traces()
95+
if 'total_tokens' in traces:
96+
print(f"Total tokens: {traces['total_tokens']}")
5097
51-
# Create a LangGraph graph
52-
graph = StateGraph(...)
53-
compiled_graph = graph.compile()
98+
# Use in benchmark
99+
benchmark = MyBenchmark(agent_data={"agent": agent_adapter})
100+
results = benchmark.run(tasks)
101+
```
54102
55-
agent_adapter = LangGraphAgentAdapter(compiled_graph, "agent_name")
56-
result = agent_adapter.run("What's the weather?")
103+
For stateful graphs, the adapter preserves conversation context across multiple
104+
calls using the same thread_id, enabling multi-turn interactions.
57105
58-
# Access message history
59-
for msg in agent_adapter.get_messages():
60-
print(msg['role'], msg['content'])
61-
```
106+
Message Format:
107+
LangGraph uses LangChain message types. The adapter converts to `maseval` / OpenAI format.
108+
109+
Tool calls are preserved with metadata and converted to OpenAI's tool call format.
110+
111+
Token Usage:
112+
If LangChain messages include `usage_metadata`, the adapter automatically extracts
113+
and aggregates token counts. This is available for models that provide usage information.
114+
115+
Requires:
116+
langgraph to be installed: `pip install maseval[langgraph]`
62117
"""
63118

64119
def __init__(self, agent_instance, name: str, callbacks=None, config=None):

0 commit comments

Comments
 (0)