composio-langgraph 0.3.29__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of composio-langgraph might be problematic. Click here for more details.

@@ -26,7 +26,7 @@ class ComposioToolSet(BaseComposioToolSet):
26
26
 
27
27
  composio_toolset = ComposioToolSet()
28
28
  tools = composio_toolset.get_actions(
29
- actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]
29
+ actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]
30
30
  )
31
31
  tool_executor = ToolExecutor(tools)
32
32
  functions = [convert_to_openai_function(t) for t in tools]
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.1
2
+ Name: composio_langgraph
3
+ Version: 0.4.0
4
+ Summary: Use Composio to get array of tools with LnagGraph Agent Workflows
5
+ Home-page: https://github.com/ComposioHQ/composio
6
+ Author: Sawradip
7
+ Author-email: sawradip@composio.dev
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9,<4
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: composio-langchain ==0.4.0
14
+ Requires-Dist: langgraph
15
+
16
+ ## 🦜🕸️ Using Composio With LangGraph
17
+
18
+ Integrate Composio with LangGraph Agentic workflows & enable them to interact seamlessly with external apps, enhancing their functionality and reach.
19
+
20
+ ### Goal
21
+
22
+ - **Star a repository on GitHub** using natural language commands through a LangGraph Agent.
23
+
24
+ ### Installation and Setup
25
+
26
+ Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
27
+
28
+ ```bash
29
+ # Install Composio LangGraph package
30
+ pip install composio-langgraph
31
+
32
+ # Connect your GitHub account
33
+ composio-cli add github
34
+
35
+ # View available applications you can connect with
36
+ composio-cli show-apps
37
+ ```
38
+
39
+ ### Usage Steps
40
+
41
+ #### 1. Import Base Packages
42
+
43
+ Prepare your environment by initializing necessary imports from LangGraph & LangChain for setting up your agent.
44
+
45
+ ```python
46
+ from typing import Literal
47
+
48
+ from langchain_openai import ChatOpenAI
49
+ from langgraph.graph import MessagesState, StateGraph
50
+ from langgraph.prebuilt import ToolNode
51
+ ```
52
+
53
+ #### 2. Fetch GitHub LangGraph Tools via Composio
54
+
55
+ Access GitHub tools provided by Composio for LangGraph, initialize a `ToolNode` with necessary tools obtaned from `ComposioToolSet`.
56
+
57
+ ```python
58
+ from composio_langgraph import Action, ComposioToolSet
59
+
60
+ # Initialize the toolset for GitHub
61
+ composio_toolset = ComposioToolSet()
62
+ tools = composio_toolset.get_actions(
63
+ actions=[
64
+ Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER,
65
+ Action.GITHUB_USERS_GET_AUTHENTICATED,
66
+ ])
67
+ tool_node = ToolNode(tools)
68
+ ```
69
+
70
+ #### 3. Prepare the model
71
+
72
+ Initialize the LLM class and bind obtained tools to the model.
73
+
74
+ ```python
75
+ model = ChatOpenAI(temperature=0, streaming=True)
76
+ model_with_tools = model.bind_tools(functions)
77
+ ```
78
+ #### 4. Define the Graph Nodes
79
+
80
+ LangGraph expects you to define different nodes of the agentic workflow as separate functions. Here we define a node for calling the LLM model.
81
+
82
+ ```python
83
+ def call_model(state: MessagesState):
84
+ messages = state["messages"]
85
+ response = model_with_tools.invoke(messages)
86
+ return {"messages": [response]}
87
+ ```
88
+ #### 5. Define the Graph Nodes and Edges
89
+
90
+ To establish the agent's workflow, we begin by initializing the workflow with `agent` and `tools` node, followed by specifying the connecting edges between nodes, finally compiling the workflow. These edges can be straightforward or conditional, depending on the workflow requirements.
91
+
92
+ ```python
93
+ def should_continue(state: MessagesState) -> Literal["tools", "__end__"]:
94
+ messages = state["messages"]
95
+ last_message = messages[-1]
96
+ if last_message.tool_calls:
97
+ return "tools"
98
+ return "__end__"
99
+
100
+
101
+ workflow = StateGraph(MessagesState)
102
+
103
+ # Define the two nodes we will cycle between
104
+ workflow.add_node("agent", call_model)
105
+ workflow.add_node("tools", tool_node)
106
+
107
+ workflow.add_edge("__start__", "agent")
108
+ workflow.add_conditional_edges(
109
+ "agent",
110
+ should_continue,
111
+ )
112
+ workflow.add_edge("tools", "agent")
113
+
114
+ app = workflow.compile()
115
+ ```
116
+ #### 6. Invoke & Check Response
117
+
118
+ After the compilation of workflow, we invoke the LLM with a task, and stream the response.
119
+
120
+ ```python
121
+ for chunk in app.stream(
122
+ {
123
+ "messages": [
124
+ (
125
+ "human",
126
+ # "Star the Github Repository composiohq/composio",
127
+ "Get my information.",
128
+ )
129
+ ]
130
+ },
131
+ stream_mode="values",
132
+ ):
133
+ chunk["messages"][-1].pretty_print()
134
+ ```
@@ -0,0 +1,6 @@
1
+ composio_langgraph/__init__.py,sha256=sjr9YY5lPNx-vI75_pmbFgPWUaEuh0WIUozsskDlQOE,211
2
+ composio_langgraph/toolset.py,sha256=LuodCh6SP8LkOKpKPP1UpqkPaqQejVTrlKe8yVQpdrg,3628
3
+ composio_langgraph-0.4.0.dist-info/METADATA,sha256=_CdOdGVpfqbTWZia62j1JvZgd8lFSCFHxAKkFAEG2Yc,3955
4
+ composio_langgraph-0.4.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
5
+ composio_langgraph-0.4.0.dist-info/top_level.txt,sha256=fT5qLVROO6_k0FCyW8_fOkGRJc_lxwWX-c6R6kN-llc,19
6
+ composio_langgraph-0.4.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (71.1.0)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,164 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: composio_langgraph
3
- Version: 0.3.29
4
- Summary: Use Composio to get array of tools with LnagGraph Agent Workflows
5
- Home-page: https://github.com/ComposioHQ/composio
6
- Author: Sawradip
7
- Author-email: sawradip@composio.dev
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: Apache Software License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.9,<4
12
- Description-Content-Type: text/markdown
13
- Requires-Dist: langchain-core >=0.2.17
14
- Requires-Dist: composio-langchain ==0.3.29
15
-
16
- ## 🦜🕸️ Using Composio With LangGraph
17
-
18
- Integrate Composio with LangGraph Agentic workflows & enable them to interact seamlessly with external apps, enhancing their functionality and reach.
19
-
20
- ### Goal
21
-
22
- - **Star a repository on GitHub** using natural language commands through a LangGraph Agent.
23
-
24
- ### Installation and Setup
25
-
26
- Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
27
-
28
- ```bash
29
- # Install Composio LangGraph package
30
- pip install composio-langgraph
31
-
32
- # Connect your GitHub account
33
- composio-cli add github
34
-
35
- # View available applications you can connect with
36
- composio-cli show-apps
37
- ```
38
-
39
- ### Usage Steps
40
-
41
- #### 1. Import Base Packages
42
-
43
- Prepare your environment by initializing necessary imports from LangGraph & LangChain for setting up your agent.
44
-
45
- ```python
46
- from langchain.agents import create_openai_functions_agent, AgentExecutor
47
- import json
48
- import operator
49
- from typing import Annotated, TypedDict, Sequence
50
-
51
- from langchain_openai import ChatOpenAI
52
- from langchain_core.utils.function_calling import convert_to_openai_function
53
- from langchain_core.messages import BaseMessage, HumanMessage, FunctionMessage
54
-
55
- from langgraph.graph import StateGraph, END
56
- from langgraph.prebuilt import ToolInvocation, ToolExecutor
57
- ```
58
-
59
- #### 2. Fetch GitHub LangGraph Tools via Composio
60
-
61
- Access GitHub tools provided by Composio for LangGraph, initialize a `tool_executor` and get OpenAI-format function schemas from the tools.
62
-
63
- ```python
64
- from composio_langgraph import Action, ComposioToolSet
65
-
66
- # Initialize the toolset for GitHub
67
- composio_toolset = ComposioToolSet()
68
- tools = composio_toolset.get_actions(
69
- actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]
70
- )
71
- tool_executor = ToolExecutor(tools)
72
- functions = [convert_to_openai_function(t) for t in tools]
73
- ```
74
-
75
- #### 3. Prepare the model
76
-
77
- Initialize the LLM class and bind obtained functions to the model.
78
-
79
- ```python
80
- model = ChatOpenAI(temperature=0, streaming=True)
81
- model = model.bind_functions(functions)
82
- ```
83
- #### 4. Define the Graph Nodes
84
-
85
- LangGraph expects you to define different nodes of the agentic workflow as separate functions.
86
-
87
- Here we define one node for calling the LLM and another for executing the correct tool(function), with appropriate parameters.
88
-
89
- ```python
90
- def function_1(state):
91
- messages = state['messages']
92
- response = model.invoke(messages)
93
- return {"messages": [response]}
94
-
95
-
96
- def function_2(state):
97
- messages = state['messages']
98
- last_message = messages[-1]
99
-
100
- parsed_function_call = last_message.additional_kwargs["function_call"]
101
-
102
- action = ToolInvocation(
103
- tool=parsed_function_call["name"],
104
- tool_input=json.loads(parsed_function_call["arguments"]),
105
- )
106
-
107
- response = tool_executor.invoke(action)
108
-
109
- function_message = FunctionMessage(content=str(response), name=action.tool)
110
-
111
- return {"messages": [function_message]}
112
-
113
- ```
114
- #### 5. Define the Graph Edges
115
-
116
- To establish the agent's workflow, we begin by initializing the workflow with an `AgentState` to maintain state, followed by specifying the connecting edges between nodes. These edges can be straightforward or conditional, depending on the workflow requirements.
117
-
118
- ```python
119
-
120
- def where_to_go(state):
121
- messages = state['messages']
122
- last_message = messages[-1]
123
-
124
- if "function_call" in last_message.additional_kwargs:
125
- return "continue"
126
- else:
127
- return "end"
128
-
129
-
130
- class AgentState(TypedDict):
131
- messages: Annotated[Sequence[BaseMessage], operator.add]
132
-
133
-
134
- workflow = StateGraph(AgentState)
135
- workflow.add_node("agent", function_1)
136
- workflow.add_node("tool", function_2)
137
- workflow.add_conditional_edges(
138
- "agent",
139
- where_to_go,
140
- {
141
- "continue": "tool",
142
- "end": END
143
- }
144
- )
145
- workflow.add_edge('tool', 'agent')
146
- workflow.set_entry_point("agent")
147
-
148
- app = workflow.compile()
149
- ```
150
- #### 6. Invoke & Check Response
151
-
152
- After the compilation of workflow, we invoke the LLM with a task, and print the final response.
153
-
154
- ```python
155
- inputs = {
156
- "messages": [
157
- HumanMessage(
158
- content="Star the Github repository sawradip/sawradip"
159
- )
160
- ]
161
- }
162
- response = app.invoke(inputs)
163
- print(response)
164
- ```
@@ -1,6 +0,0 @@
1
- composio_langgraph/__init__.py,sha256=sjr9YY5lPNx-vI75_pmbFgPWUaEuh0WIUozsskDlQOE,211
2
- composio_langgraph/toolset.py,sha256=Ud3wFuFIiOm4InjhiNZGSjLzUElDL1YR84LEsOEyb88,3625
3
- composio_langgraph-0.3.29.dist-info/METADATA,sha256=DJN41QD8GejDyNfWU5xI0KdPG0iQfwt6lgb5qQZo2wc,4758
4
- composio_langgraph-0.3.29.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
5
- composio_langgraph-0.3.29.dist-info/top_level.txt,sha256=fT5qLVROO6_k0FCyW8_fOkGRJc_lxwWX-c6R6kN-llc,19
6
- composio_langgraph-0.3.29.dist-info/RECORD,,