Skip to content

Commit f0aad90

Browse files
committed
fix(chat-agent): support file-based graph loading in LangSmith
1 parent 47fccd1 commit f0aad90

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

examples/chat-agent/src/chat_agent/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from langgraph.checkpoint.memory import MemorySaver
99
from langgraph.graph import END, START, MessagesState, StateGraph
1010

11-
from .config import Configuration
11+
from chat_agent.config import Configuration
1212

1313
load_dotenv()
1414

examples/chat-agent/tests/test_agent.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22
import uuid
3+
from importlib.util import module_from_spec, spec_from_file_location
4+
from pathlib import Path
35

46
import pytest
57

@@ -13,6 +15,19 @@ def test_config_importable():
1315
assert "system_prompt" in Configuration.__annotations__
1416

1517

18+
def test_graph_loads_from_file_spec():
19+
"""LangGraph Cloud loads graph files directly, so file-spec import must work."""
20+
agent_path = Path(__file__).resolve().parents[1] / "src" / "chat_agent" / "agent.py"
21+
spec = spec_from_file_location("deployed_agent", agent_path)
22+
assert spec is not None
23+
assert spec.loader is not None
24+
25+
module = module_from_spec(spec)
26+
spec.loader.exec_module(module)
27+
28+
assert hasattr(module, "graph")
29+
30+
1631
@pytest.mark.skipif(not os.getenv("OPENAI_API_KEY"), reason=SKIP_REASON)
1732
def test_single_turn():
1833
"""Graph compiles and LLM returns a non-empty AIMessage."""

0 commit comments

Comments
 (0)