(
checkpointer_value, events_list, expected_messages
)
| 217 | ) |
| 218 | @pytest.mark.asyncio |
| 219 | async def test_langgraph_agent( |
| 220 | checkpointer_value, events_list, expected_messages |
| 221 | ): |
| 222 | mock_graph = MagicMock(spec=CompiledGraph) |
| 223 | mock_graph_state = MagicMock() |
| 224 | mock_graph_state.values = {} |
| 225 | mock_graph.get_state.return_value = mock_graph_state |
| 226 | |
| 227 | mock_graph.checkpointer = checkpointer_value |
| 228 | mock_graph.invoke.return_value = { |
| 229 | "messages": [AIMessage(content="test response")] |
| 230 | } |
| 231 | |
| 232 | mock_parent_context = MagicMock(spec=InvocationContext) |
| 233 | mock_parent_context._state_schema = None |
| 234 | mock_session = MagicMock() |
| 235 | mock_parent_context.session = mock_session |
| 236 | mock_parent_context.user_content = types.Content( |
| 237 | role="user", parts=[types.Part.from_text(text="test prompt")] |
| 238 | ) |
| 239 | mock_parent_context.branch = "parent_agent" |
| 240 | mock_parent_context.end_invocation = False |
| 241 | mock_session.events = events_list |
| 242 | mock_parent_context.invocation_id = "test_invocation_id" |
| 243 | mock_parent_context.model_copy.return_value = mock_parent_context |
| 244 | mock_parent_context.plugin_manager = PluginManager(plugins=[]) |
| 245 | |
| 246 | weather_agent = LangGraphAgent( |
| 247 | name="weather_agent", |
| 248 | description="A agent that answers weather questions", |
| 249 | instruction="test system prompt", |
| 250 | graph=mock_graph, |
| 251 | ) |
| 252 | |
| 253 | result_event = None |
| 254 | async for event in weather_agent.run_async(mock_parent_context): |
| 255 | result_event = event |
| 256 | |
| 257 | assert result_event.author == "weather_agent" |
| 258 | assert result_event.content.parts[0].text == "test response" |
| 259 | |
| 260 | mock_graph.invoke.assert_called_once() |
| 261 | mock_graph.invoke.assert_called_with( |
| 262 | {"messages": expected_messages}, |
| 263 | {"configurable": {"thread_id": mock_session.id}}, |
| 264 | ) |
nothing calls this directly
no test coverage detected