From 0d91fc7b79b610b78b274506d09f0353fc0505fa Mon Sep 17 00:00:00 2001 From: goulustis Date: Wed, 22 Oct 2025 12:53:44 +0800 Subject: [PATCH] moved invoke --- lang_agent/graphs/react.py | 15 +++++++++++++-- lang_agent/pipeline.py | 18 +++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lang_agent/graphs/react.py b/lang_agent/graphs/react.py index c462cf3..29804d1 100644 --- a/lang_agent/graphs/react.py +++ b/lang_agent/graphs/react.py @@ -49,5 +49,16 @@ class ReactGraph(GraphBase): tools = self.tool_manager.get_langchain_tools() self.agent = create_agent(self.llm, tools, checkpointer=memory) - def get_graph(self): - return self.agent + def invoke(self, *nargs, as_stream:bool=False, **kwargs): + """ + as_stream (bool): for debug only, gets the agent to print its thoughts + """ + + if as_stream: + for step in self.agent.stream(*nargs, stream_mode="values", **kwargs): + step["messages"][-1].pretty_print() + out = step + else: + out = self.agent.invoke(*nargs, **kwargs) + + return out diff --git a/lang_agent/pipeline.py b/lang_agent/pipeline.py index 4377f5d..33e2d90 100644 --- a/lang_agent/pipeline.py +++ b/lang_agent/pipeline.py @@ -63,24 +63,12 @@ class Pipeline: self.config.graph_config.base_url = self.config.base_url if self.config.base_url is not None else self.config.graph_config.base_url self.config.graph_config.api_key = self.config.api_key - graph:ReactGraph = self.config.graph_config.setup() - self.agent = graph.get_graph() + self.graph:ReactGraph = self.config.graph_config.setup() - def invoke(self, *nargs, as_stream:bool=False, **kwargs): - """ - as_stream (bool): for debug only, gets the agent to print its thoughts - """ - - if as_stream: - for step in self.agent.stream(*nargs, stream_mode="values", **kwargs): - step["messages"][-1].pretty_print() - out = step - else: - out = self.agent.invoke(*nargs, **kwargs) - - return out + def invoke(self, *nargs, **kwargs): + return self.graph.invoke(*nargs, **kwargs) async def handle_connection(self, websocket:ServerConnection): try: