Skip to main content

No project description provided

Project description

Langgraph extensions

Get Pocket Subgraph

from hyperpocket.tool import from_git

from hyperpocket_langgraph import PocketLanggraph

pocket = PocketLanggraph(tools=[
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
  "https://github.com/my-org/some-awesome-tool",
])

# get tool node from pocket
pocket_node = pocket.get_tool_node()

Binding Pocket Tools

import os

from hyperpocket.tool import from_git
from langchain_openai import ChatOpenAI

from hyperpocket_langgraph import PocketLanggraph

pocket = PocketLanggraph(tools=[
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
])

# get tools from pocket to bind llm
tools = pocket.get_tools()
llm = ChatOpenAI(model="gpt-4o", api_key=os.getenv("OPENAI_API_KEY"))

# bind pocket tools with llm
llm_with_tools = llm.bind_tools(tools)

Examples

import os
from typing import Annotated

from hyperpocket.tool import from_git
from langchain_core.runnables import RunnableConfig
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import tools_condition
from typing_extensions import TypedDict

from hyperpocket_langgraph import PocketLanggraph

# Define pocket tools
pocket = PocketLanggraph(tools=[
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
])

# Get Pocket ToolNode
pocket_node = pocket.get_tool_node()


# Define your own langgraph state
class State(TypedDict):
  messages: Annotated[list, add_messages]


# Biding Pocket Tools
tools = pocket.get_tools()
llm = ChatOpenAI(model="gpt-4o", api_key=os.getenv("OPENAI_API_KEY"))
llm_with_tools = llm.bind_tools(tools)


# Make your langgraph with pocket nodes and bound llm
def chatbot(state: State):
  return {"messages": [llm_with_tools.invoke(state["messages"])]}


graph_builder = StateGraph(State)
graph_builder.add_node("chatbot", chatbot)

# add pocket tool node
graph_builder.add_node("tools", pocket_node)

graph_builder.add_conditional_edges(
  "chatbot",
  tools_condition,
)

graph_builder.add_edge("tools", "chatbot")
graph_builder.add_edge(START, "chatbot")
graph_builder.add_edge("chatbot", END)

memory = MemorySaver()
graph = graph_builder.compile(checkpointer=memory)
config = RunnableConfig(
  recursion_limit=30,
  configurable={"thread_id": "1"},  # edit thread_id by user if needed
)

Authentication Flow Control

In Pocket, you can configure whether authentication operates in a multi-turn manner or as human-in-the-loop

by setting the should_interrupt flag when calling get_tool_node

Multi-turn

Perform authentication in a multi-turn way

from hyperpocket.tool import from_git

from hyperpocket_langgraph import PocketLanggraph

# Define pocket tools
pocket = PocketLanggraph(tools=[
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
])

# Get Pocket ToolNode
pocket_node = pocket.get_tool_node(should_interrupt=False)  # multi turn 

Human-in-the-loop Auth

from hyperpocket.tool import from_git

from hyperpocket_langgraph import PocketLanggraph

# Define pocket tools
pocket = PocketLanggraph(tools=[
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
  from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
])

# Get Pocket ToolNode
pocket_node = pocket.get_tool_node(should_interrupt=True)  # Human-in-the-loop 

Differences between multi-turn and human-in-the-loop

The two approaches may not differ significantly in terms of user experience, but they are fundamentally distinct internally.

In the case of the multi-turn way, the decision to return to an ongoing authentication(auth) flow is delegated to the agent.

As a result, if the user want to cancel or modify the auth process midway, then agent can adapt the auth flow to incorporate those changes.


However, with the human-in-the-loop way, it simply resumes from an interrupted point, proceeding directly with the previous flow regardless of user input.

(Currently, users need to manually provide any input to move forward, but future updates aim to automate this transition once the user's task is complete.)

Therefore, in the human-in-the-loop way, users cannot modify or cancel the auth flow once it's resumed.


That said, the multi-turn approach has its drawbacks as well. Since the agent determines whether to re-enter the auth flow, there is a risk of incorrect decisions being made.

Conversely, the human-in-the-loop approach eliminates this risk by always continuing the previous flow as it is, offering more predictable and controlled behavior for managing the auth flow.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hyperpocket_langgraph-0.1.8.tar.gz (68.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyperpocket_langgraph-0.1.8-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file hyperpocket_langgraph-0.1.8.tar.gz.

File metadata

File hashes

Hashes for hyperpocket_langgraph-0.1.8.tar.gz
Algorithm Hash digest
SHA256 e9a867b782d8f12c51be6b6de6c5b01d10d90e3a2a0a4b5f4ef5cab5e2ab86f2
MD5 8fe2df492b07ce42b27824fa26d5ef5b
BLAKE2b-256 feff5063b4529f57a9978a7bba6fab2965e778f6cadfdb147867daeb1a1fe701

See more details on using hashes here.

File details

Details for the file hyperpocket_langgraph-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for hyperpocket_langgraph-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 dd203b143a6b1c1dce3a04e32752506889834b276723bcfa8fb54777551e6c7b
MD5 3eb8b3786816a9050de13fed8197a07e
BLAKE2b-256 064813a3c2dd47d4d30203dba04d8ebe2d8bab550a45ac1a5776c4f628ea85d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page