Skip to content

Conversation

@ryoppippi
Copy link
Member

@ryoppippi ryoppippi commented Sep 2, 2025

This PR adds first-class LangGraph support:

  • New helpers in stackone_ai.integrations.langgraph:
    • to_tool_node and to_tool_executor
    • bind_model_with_tools and create_react_agent
  • Updated example: examples/langgraph_tool_node.py now builds a ToolNode and ToolExecutor
  • README: LangGraph section with a minimal agent loop (tools_condition + typed state)
  • pyproject: include langgraph in the examples extra

Motivation

  • Make it trivial to plug StackOne tools into LangGraph prebuilt nodes.
  • Provide a minimal, conventional graph pattern (LLM -> tools -> LLM) that aligns with the docs.

Notes

  • Helpers accept either our Tools collection or plain LangChain tools.
  • Functions perform local imports to keep base installation light.

Testing

  • Pre-commit hooks pass (ruff, mypy).

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

    • Added helpers: to_tool_node, to_tool_executor, bind_model_with_tools, create_react_agent.
    • Updated example (examples/langgraph_tool_node.py) to build a ToolNode and ToolExecutor.
    • README: new LangGraph section with a minimal typed-state agent loop using tools_condition.
    • Helpers accept StackOne Tools or LangChain tools and use local imports to keep the base install light.
  • Dependencies

    • Added langgraph>=0.2.0 to the examples extra.

Copilot AI review requested due to automatic review settings September 2, 2025 21:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.langgraph for 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
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a bare Exception catch is too broad. Consider catching ImportError or ModuleNotFoundError specifically since this is checking for missing dependencies.

Suggested change
except Exception as e: # pragma: no cover
except ImportError as e: # pragma: no cover

Copilot uses AI. Check for mistakes.
if TYPE_CHECKING: # pragma: no cover - only for typing
try:
from langgraph.prebuilt import ToolExecutor, ToolNode
except Exception: # pragma: no cover
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a bare Exception catch is too broad. Consider catching ImportError or ModuleNotFoundError specifically since this is checking for missing dependencies.

Suggested change
except Exception: # pragma: no cover
except ImportError: # pragma: no cover

Copilot uses AI. Check for mistakes.
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

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]}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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[&quot;messages&quot;] + [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=&quot;gpt-4o-mini&quot;)
+    llm = bind_model_with_tools(llm, langchain_tools)
+    resp = llm.invoke(state[&quot;messages&quot;])  # returns AIMessage with optional tool_calls
+    return {&quot;messages&quot;: state[&quot;messages&quot;] + [resp]}
+
+graph.add_node(&quot;llm&quot;, call_llm)
</file context>
Suggested change
return {"messages": state["messages"] + [resp]}
return {"messages": [resp]}

@ryoppippi ryoppippi force-pushed the feat/langgraph-integration branch 2 times, most recently from 82f08cd to 8371e81 Compare September 2, 2025 21:49
- 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
@ryoppippi ryoppippi force-pushed the feat/langgraph-integration branch from 8371e81 to 8bb3c02 Compare September 2, 2025 21:51
…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
Copy link
Contributor

@glebedel glebedel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ryoppippi
Copy link
Member Author

SCR-20250905-nevl hmm still error

- 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
@ryoppippi
Copy link
Member Author

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
@ryoppippi ryoppippi force-pushed the feat/langgraph-integration branch from 0fd75fc to f55b44d Compare September 5, 2025 14:06
@ryoppippi ryoppippi enabled auto-merge (squash) September 26, 2025 13:38
@ryoppippi ryoppippi merged commit 983e2f7 into main Sep 26, 2025
5 checks passed
@ryoppippi ryoppippi deleted the feat/langgraph-integration branch September 26, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants