feat: LangGraph integration helpers and example#33
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces first-class LangGraph integration for StackOne tools, making it easy to use StackOne tools within LangGraph workflows and agents.
- Adds new integration helpers in
stackone_ai.integrations.langgraphfor converting tools to LangGraph components - Updates the example to demonstrate actual LangGraph integration with ToolNode and ToolExecutor
- Includes comprehensive documentation with a complete agent loop example in the README
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| stackone_ai/integrations/langgraph.py | New module with helper functions to convert StackOne tools to LangGraph prebuilt components |
| stackone_ai/integrations/init.py | New init file exposing the LangGraph integration helpers |
| pyproject.toml | Adds langgraph dependency to the examples extra |
| examples/langgraph_tool_node.py | Updated example demonstrating ToolNode and ToolExecutor creation |
| README.md | Adds LangGraph integration section with complete agent loop example |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| def _ensure_langgraph() -> None: | ||
| try: | ||
| from langgraph import prebuilt as _ # noqa: F401 | ||
| except Exception as e: # pragma: no cover |
There was a problem hiding this comment.
Using a bare Exception catch is too broad. Consider catching ImportError or ModuleNotFoundError specifically since this is checking for missing dependencies.
| except Exception as e: # pragma: no cover | |
| except ImportError as e: # pragma: no cover |
| if TYPE_CHECKING: # pragma: no cover - only for typing | ||
| try: | ||
| from langgraph.prebuilt import ToolExecutor, ToolNode | ||
| except Exception: # pragma: no cover |
There was a problem hiding this comment.
Using a bare Exception catch is too broad. Consider catching ImportError or ModuleNotFoundError specifically since this is checking for missing dependencies.
| except Exception: # pragma: no cover | |
| except ImportError: # pragma: no cover |
| llm = ChatOpenAI(model="gpt-4o-mini") | ||
| llm = bind_model_with_tools(llm, langchain_tools) | ||
| resp = llm.invoke(state["messages"]) # returns AIMessage with optional tool_calls | ||
| return {"messages": state["messages"] + [resp]} |
There was a problem hiding this comment.
With add_messages, returning state["messages"] + [resp] duplicates messages; return only the new message so the reducer can append it.
Prompt for AI agents
Address the following comment on README.md at line 146:
<comment>With add_messages, returning state["messages"] + [resp] duplicates messages; return only the new message so the reducer can append it.</comment>
<file context>
@@ -110,6 +110,52 @@ for tool_call in response.tool_calls:
+ llm = ChatOpenAI(model="gpt-4o-mini")
+ llm = bind_model_with_tools(llm, langchain_tools)
+ resp = llm.invoke(state["messages"]) # returns AIMessage with optional tool_calls
+ return {"messages": state["messages"] + [resp]}
+
+graph.add_node("llm", call_llm)
</file context>
| return {"messages": state["messages"] + [resp]} | |
| return {"messages": [resp]} |
82f08cd to
8371e81
Compare
- Add stackone_ai/integrations/langgraph with: - to_tool_node, to_tool_executor - bind_model_with_tools, create_react_agent - Add examples/langgraph_tool_node.py matching README snippet (English comments) - Update README with a minimal LangGraph agent loop (tools_condition) and prereqs - examples now document installing langgraph and langchain-openai explicitly
8371e81 to
8bb3c02
Compare
…ed ToolExecutor - Replace ToolExecutor import with ToolNode in TYPE_CHECKING block - Update to_tool_executor function to return ToolNode instead of deprecated ToolExecutor - Add mypy override to ignore missing imports for langgraph modules - Fix linting issue with blank line whitespace in docstring
- Use class-based fallback instead of assignment for ToolNode in TYPE_CHECKING block - Add type: ignore for no-redef to handle the intentional redefinition - This fixes compatibility with Python 3.9 mypy type checking
- Run mypy on server.py only for Python 3.10+ where MCP dependencies are available - Exclude server.py for Python 3.9 to avoid MCP import errors - This ensures type checking works correctly across all supported Python versions
|
hmm this is bad, i'll fix it |
- Add comprehensive mypy overrides for mcp module - Configure mypy to install types automatically in CI - Exclude .venv directory from type checking - This resolves pattern matching syntax errors from mcp library dependencies
- Remove unused type: ignore comment for try block - Add type: ignore for MCP decorator functions to handle untyped decorators - Set mypy python_version to 3.10 to properly handle pattern matching syntax - All mypy checks now pass successfully
0fd75fc to
f55b44d
Compare

This PR adds first-class LangGraph support:
Motivation
Notes
Testing
Summary by cubic
Adds first-class LangGraph integration to make StackOne tools plug-and-play with LangGraph prebuilt nodes. Enables a simple LLM -> tools -> LLM loop with minimal setup.
New Features
Dependencies