Skip to content

revert: "feat: Add tracing to LLM invoke" #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
BaseMessage,
SystemMessage,
)
from langchain_core.runnables import RunnableConfig
from langchain_core.tools import BaseTool
from langgraph.graph import START, StateGraph
from langgraph.graph.state import CompiledStateGraph
from langgraph.prebuilt.tool_node import tools_condition

from rai.agents.langchain.core.tool_runner import ToolRunner
from rai.agents.langchain.invocation_helpers import invoke_llm_with_tracing


class State(TypedDict):
Expand All @@ -42,7 +40,6 @@ def agent(
logger: logging.Logger,
system_prompt: str | SystemMessage,
state: State,
config: RunnableConfig,
):
logger.info("Running thinker")

Expand All @@ -58,9 +55,7 @@ def agent(
else system_prompt
)
state["messages"].insert(0, system_msg)

# Invoke LLM with tracing if it is configured and available
ai_msg = invoke_llm_with_tracing(llm, state["messages"], config)
ai_msg = llm.invoke(state["messages"])
state["messages"].append(ai_msg)
return state

Expand Down
10 changes: 2 additions & 8 deletions src/rai_core/rai/agents/langchain/core/react_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

from langchain_core.language_models import BaseChatModel
from langchain_core.messages import BaseMessage, SystemMessage
from langchain_core.runnables import Runnable, RunnableConfig
from langchain_core.runnables import Runnable
from langchain_core.tools import BaseTool
from langgraph.graph import START, StateGraph
from langgraph.prebuilt.tool_node import tools_condition

from rai.agents.langchain.core.tool_runner import ToolRunner
from rai.agents.langchain.invocation_helpers import invoke_llm_with_tracing
from rai.initialization import get_llm_model
from rai.messages import SystemMultimodalMessage

Expand All @@ -49,7 +48,6 @@ def llm_node(
llm: BaseChatModel,
system_prompt: Optional[str | SystemMultimodalMessage],
state: ReActAgentState,
config: RunnableConfig,
):
"""Process messages using the LLM.

Expand All @@ -59,8 +57,6 @@ def llm_node(
The language model to use for processing
state : ReActAgentState
Current state containing messages
config : RunnableConfig
Configuration including callbacks for tracing

Returns
-------
Expand All @@ -79,9 +75,7 @@ def llm_node(
# at this point, state['messages'] length should at least be 1
if not isinstance(state["messages"][0], SystemMessage):
state["messages"].insert(0, SystemMessage(content=system_prompt))

# Invoke LLM with tracing if it is configured and available
ai_msg = invoke_llm_with_tracing(llm, state["messages"], config)
ai_msg = llm.invoke(state["messages"])
state["messages"].append(ai_msg)


Expand Down
10 changes: 2 additions & 8 deletions src/rai_core/rai/agents/langchain/core/state_based_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@

from langchain_core.language_models import BaseChatModel
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage
from langchain_core.runnables import Runnable, RunnableConfig
from langchain_core.runnables import Runnable
from langchain_core.tools import BaseTool
from langgraph.graph import START, StateGraph
from langgraph.prebuilt.tool_node import tools_condition

from rai.agents.langchain.core.tool_runner import ToolRunner
from rai.agents.langchain.invocation_helpers import invoke_llm_with_tracing
from rai.initialization import get_llm_model
from rai.messages import HumanMultimodalMessage, SystemMultimodalMessage

Expand All @@ -53,7 +52,6 @@ def llm_node(
llm: BaseChatModel,
system_prompt: Optional[str | SystemMultimodalMessage],
state: ReActAgentState,
config: RunnableConfig,
):
"""Process messages using the LLM.

Expand All @@ -63,8 +61,6 @@ def llm_node(
The language model to use for processing
state : ReActAgentState
Current state containing messages
config : RunnableConfig
Configuration including callbacks for tracing

Returns
-------
Expand All @@ -83,9 +79,7 @@ def llm_node(
# at this point, state['messages'] length should at least be 1
if not isinstance(state["messages"][0], SystemMessage):
state["messages"].insert(0, SystemMessage(content=system_prompt))

# Invoke LLM with tracing if it is configured and available
ai_msg = invoke_llm_with_tracing(llm, state["messages"], config)
ai_msg = llm.invoke(state["messages"])
state["messages"].append(ai_msg)


Expand Down
74 changes: 0 additions & 74 deletions src/rai_core/rai/agents/langchain/invocation_helpers.py

This file was deleted.

Loading