composio-langgraph 0.3.30__tar.gz → 0.4.0__tar.gz

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.

@@ -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,119 @@
1
+ ## 🦜🕸️ Using Composio With LangGraph
2
+
3
+ Integrate Composio with LangGraph Agentic workflows & enable them to interact seamlessly with external apps, enhancing their functionality and reach.
4
+
5
+ ### Goal
6
+
7
+ - **Star a repository on GitHub** using natural language commands through a LangGraph Agent.
8
+
9
+ ### Installation and Setup
10
+
11
+ Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
12
+
13
+ ```bash
14
+ # Install Composio LangGraph package
15
+ pip install composio-langgraph
16
+
17
+ # Connect your GitHub account
18
+ composio-cli add github
19
+
20
+ # View available applications you can connect with
21
+ composio-cli show-apps
22
+ ```
23
+
24
+ ### Usage Steps
25
+
26
+ #### 1. Import Base Packages
27
+
28
+ Prepare your environment by initializing necessary imports from LangGraph & LangChain for setting up your agent.
29
+
30
+ ```python
31
+ from typing import Literal
32
+
33
+ from langchain_openai import ChatOpenAI
34
+ from langgraph.graph import MessagesState, StateGraph
35
+ from langgraph.prebuilt import ToolNode
36
+ ```
37
+
38
+ #### 2. Fetch GitHub LangGraph Tools via Composio
39
+
40
+ Access GitHub tools provided by Composio for LangGraph, initialize a `ToolNode` with necessary tools obtaned from `ComposioToolSet`.
41
+
42
+ ```python
43
+ from composio_langgraph import Action, ComposioToolSet
44
+
45
+ # Initialize the toolset for GitHub
46
+ composio_toolset = ComposioToolSet()
47
+ tools = composio_toolset.get_actions(
48
+ actions=[
49
+ Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER,
50
+ Action.GITHUB_USERS_GET_AUTHENTICATED,
51
+ ])
52
+ tool_node = ToolNode(tools)
53
+ ```
54
+
55
+ #### 3. Prepare the model
56
+
57
+ Initialize the LLM class and bind obtained tools to the model.
58
+
59
+ ```python
60
+ model = ChatOpenAI(temperature=0, streaming=True)
61
+ model_with_tools = model.bind_tools(functions)
62
+ ```
63
+ #### 4. Define the Graph Nodes
64
+
65
+ LangGraph expects you to define different nodes of the agentic workflow as separate functions. Here we define a node for calling the LLM model.
66
+
67
+ ```python
68
+ def call_model(state: MessagesState):
69
+ messages = state["messages"]
70
+ response = model_with_tools.invoke(messages)
71
+ return {"messages": [response]}
72
+ ```
73
+ #### 5. Define the Graph Nodes and Edges
74
+
75
+ 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.
76
+
77
+ ```python
78
+ def should_continue(state: MessagesState) -> Literal["tools", "__end__"]:
79
+ messages = state["messages"]
80
+ last_message = messages[-1]
81
+ if last_message.tool_calls:
82
+ return "tools"
83
+ return "__end__"
84
+
85
+
86
+ workflow = StateGraph(MessagesState)
87
+
88
+ # Define the two nodes we will cycle between
89
+ workflow.add_node("agent", call_model)
90
+ workflow.add_node("tools", tool_node)
91
+
92
+ workflow.add_edge("__start__", "agent")
93
+ workflow.add_conditional_edges(
94
+ "agent",
95
+ should_continue,
96
+ )
97
+ workflow.add_edge("tools", "agent")
98
+
99
+ app = workflow.compile()
100
+ ```
101
+ #### 6. Invoke & Check Response
102
+
103
+ After the compilation of workflow, we invoke the LLM with a task, and stream the response.
104
+
105
+ ```python
106
+ for chunk in app.stream(
107
+ {
108
+ "messages": [
109
+ (
110
+ "human",
111
+ # "Star the Github Repository composiohq/composio",
112
+ "Get my information.",
113
+ )
114
+ ]
115
+ },
116
+ stream_mode="values",
117
+ ):
118
+ chunk["messages"][-1].pretty_print()
119
+ ```
@@ -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,2 @@
1
+ composio_langchain==0.4.0
2
+ langgraph
@@ -9,7 +9,7 @@ from setuptools import setup
9
9
 
10
10
  setup(
11
11
  name="composio_langgraph",
12
- version="0.3.30",
12
+ version="0.4.0",
13
13
  author="Sawradip",
14
14
  author_email="sawradip@composio.dev",
15
15
  description="Use Composio to get array of tools with LnagGraph Agent Workflows",
@@ -23,8 +23,8 @@ setup(
23
23
  ],
24
24
  python_requires=">=3.9,<4",
25
25
  install_requires=[
26
- "langchain_core>=0.2.17",
27
- "composio_langchain==0.3.30",
26
+ "composio_langchain==0.4.0",
27
+ "langgraph",
28
28
  ],
29
29
  include_package_data=True,
30
30
  )
@@ -1,164 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: composio_langgraph
3
- Version: 0.3.30
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.30
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,149 +0,0 @@
1
- ## 🦜🕸️ Using Composio With LangGraph
2
-
3
- Integrate Composio with LangGraph Agentic workflows & enable them to interact seamlessly with external apps, enhancing their functionality and reach.
4
-
5
- ### Goal
6
-
7
- - **Star a repository on GitHub** using natural language commands through a LangGraph Agent.
8
-
9
- ### Installation and Setup
10
-
11
- Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.
12
-
13
- ```bash
14
- # Install Composio LangGraph package
15
- pip install composio-langgraph
16
-
17
- # Connect your GitHub account
18
- composio-cli add github
19
-
20
- # View available applications you can connect with
21
- composio-cli show-apps
22
- ```
23
-
24
- ### Usage Steps
25
-
26
- #### 1. Import Base Packages
27
-
28
- Prepare your environment by initializing necessary imports from LangGraph & LangChain for setting up your agent.
29
-
30
- ```python
31
- from langchain.agents import create_openai_functions_agent, AgentExecutor
32
- import json
33
- import operator
34
- from typing import Annotated, TypedDict, Sequence
35
-
36
- from langchain_openai import ChatOpenAI
37
- from langchain_core.utils.function_calling import convert_to_openai_function
38
- from langchain_core.messages import BaseMessage, HumanMessage, FunctionMessage
39
-
40
- from langgraph.graph import StateGraph, END
41
- from langgraph.prebuilt import ToolInvocation, ToolExecutor
42
- ```
43
-
44
- #### 2. Fetch GitHub LangGraph Tools via Composio
45
-
46
- Access GitHub tools provided by Composio for LangGraph, initialize a `tool_executor` and get OpenAI-format function schemas from the tools.
47
-
48
- ```python
49
- from composio_langgraph import Action, ComposioToolSet
50
-
51
- # Initialize the toolset for GitHub
52
- composio_toolset = ComposioToolSet()
53
- tools = composio_toolset.get_actions(
54
- actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]
55
- )
56
- tool_executor = ToolExecutor(tools)
57
- functions = [convert_to_openai_function(t) for t in tools]
58
- ```
59
-
60
- #### 3. Prepare the model
61
-
62
- Initialize the LLM class and bind obtained functions to the model.
63
-
64
- ```python
65
- model = ChatOpenAI(temperature=0, streaming=True)
66
- model = model.bind_functions(functions)
67
- ```
68
- #### 4. Define the Graph Nodes
69
-
70
- LangGraph expects you to define different nodes of the agentic workflow as separate functions.
71
-
72
- Here we define one node for calling the LLM and another for executing the correct tool(function), with appropriate parameters.
73
-
74
- ```python
75
- def function_1(state):
76
- messages = state['messages']
77
- response = model.invoke(messages)
78
- return {"messages": [response]}
79
-
80
-
81
- def function_2(state):
82
- messages = state['messages']
83
- last_message = messages[-1]
84
-
85
- parsed_function_call = last_message.additional_kwargs["function_call"]
86
-
87
- action = ToolInvocation(
88
- tool=parsed_function_call["name"],
89
- tool_input=json.loads(parsed_function_call["arguments"]),
90
- )
91
-
92
- response = tool_executor.invoke(action)
93
-
94
- function_message = FunctionMessage(content=str(response), name=action.tool)
95
-
96
- return {"messages": [function_message]}
97
-
98
- ```
99
- #### 5. Define the Graph Edges
100
-
101
- 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.
102
-
103
- ```python
104
-
105
- def where_to_go(state):
106
- messages = state['messages']
107
- last_message = messages[-1]
108
-
109
- if "function_call" in last_message.additional_kwargs:
110
- return "continue"
111
- else:
112
- return "end"
113
-
114
-
115
- class AgentState(TypedDict):
116
- messages: Annotated[Sequence[BaseMessage], operator.add]
117
-
118
-
119
- workflow = StateGraph(AgentState)
120
- workflow.add_node("agent", function_1)
121
- workflow.add_node("tool", function_2)
122
- workflow.add_conditional_edges(
123
- "agent",
124
- where_to_go,
125
- {
126
- "continue": "tool",
127
- "end": END
128
- }
129
- )
130
- workflow.add_edge('tool', 'agent')
131
- workflow.set_entry_point("agent")
132
-
133
- app = workflow.compile()
134
- ```
135
- #### 6. Invoke & Check Response
136
-
137
- After the compilation of workflow, we invoke the LLM with a task, and print the final response.
138
-
139
- ```python
140
- inputs = {
141
- "messages": [
142
- HumanMessage(
143
- content="Star the Github repository sawradip/sawradip"
144
- )
145
- ]
146
- }
147
- response = app.invoke(inputs)
148
- print(response)
149
- ```
@@ -1,164 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: composio_langgraph
3
- Version: 0.3.30
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.30
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,2 +0,0 @@
1
- langchain_core>=0.2.17
2
- composio_langchain==0.3.30