Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from azure.ai.agentserver.core import AgentRunContext
from azure.ai.agentserver.core.tools import OAuthConsentRequiredError # pylint:disable=import-error,no-name-in-module
from ._context import LanggraphRunContext
from ._exceptions import LangGraphMissingConversationIdError
from .models.response_api_converter import GraphInputArguments, ResponseAPIConverter
from .models.response_api_default_converter import ResponseAPIDefaultConverter
from .models.utils import is_state_schema_valid
Expand Down Expand Up @@ -67,7 +66,6 @@ async def agent_run(self, context: AgentRunContext):
# Resolve graph - always resolve if it's a factory function to get fresh graph each time
# For factories, get a new graph instance per request to avoid concurrency issues
try:
self._check_missing_thread_id(context)
lg_run_context = await self.setup_lg_run_context(context)
input_arguments = await self.converter.convert_request(lg_run_context)
self.ensure_runnable_config(input_arguments, lg_run_context)
Expand Down Expand Up @@ -117,11 +115,6 @@ def get_trace_attributes(self):
attrs["service.namespace"] = "azure.ai.agentserver.langgraph"
return attrs

def _check_missing_thread_id(self, context: AgentRunContext) -> None:
checkpointer = getattr(self._graph, "checkpointer", None)
if checkpointer and checkpointer is not False and not context.conversation_id:
raise LangGraphMissingConversationIdError()

async def agent_run_non_stream(self, input_arguments: GraphInputArguments):
"""
Run the agent with non-streaming response.
Expand Down Expand Up @@ -176,6 +169,9 @@ def ensure_runnable_config(self, input_arguments: GraphInputArguments, context:
thread_id = input_arguments["context"].agent_run.conversation_id
if thread_id:
configurable["thread_id"] = thread_id
else:
configurable["thread_id"] = f"langgraph-{input_arguments['context'].agent_run.response_id}"
logger.debug(f"Conversation ID not provided, generate one: thread_id={configurable['thread_id']}")
config["configurable"] = configurable
context.attach_to_config(config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,13 @@

import pytest

from azure.ai.agentserver.langgraph._exceptions import LangGraphMissingConversationIdError
from azure.ai.agentserver.langgraph.langgraph import LangGraphAdapter
from azure.ai.agentserver.langgraph.models.response_api_default_converter import ResponseAPIDefaultConverter


class _DummyConverter:
async def convert_request(self, context): # pragma: no cover - guard should short-circuit first
raise AssertionError("convert_request should not be called for this test")

async def convert_response_non_stream(self, output, context): # pragma: no cover - guard should short-circuit
raise AssertionError("convert_response_non_stream should not be called for this test")

async def convert_response_stream(self, output, context): # pragma: no cover - guard should short-circuit
raise AssertionError("convert_response_stream should not be called for this test")


class DummyGraphState:
def __init__(self):
self.values = "state"


class _DummyGraph:
def __init__(self) -> None:
self.checkpointer = object()
Expand Down Expand Up @@ -61,14 +47,3 @@ async def test_aget_state_uses_conversation_id() -> None:
assert state is not None
assert state.values == "state"
assert graph.last_config["configurable"]["thread_id"] == "conv-1"


@pytest.mark.unit
@pytest.mark.asyncio
async def test_agent_run_requires_conversation_id_with_checkpointer_raises() -> None:
graph = _DummyGraph()
adapter = LangGraphAdapter(graph, converter=_DummyConverter()) # type: ignore[arg-type]
context = SimpleNamespace(conversation_id=None, stream=False)

with pytest.raises(LangGraphMissingConversationIdError):
await adapter.agent_run(context)