Is it possible to hide graph state variables from langsmith logs? #2157
-
Hi, I am working on a multi-agent chat application where specific agents require user authentication to be passed to the graph. I.e. something like that: from typing import TypedDict, Literal
from langchain_core.runnables import RunnableLambda
from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langgraph.graph import StateGraph
llm = ChatOpenAI(model='gpt-4o')
class State(TypedDict):
message: str
bucket: Literal['cars', 'animals']
user_secret_key: str
answer: str
def get_user_buckets(state: State) -> dict[str, str]:
ans = ''
if state['user_secret_key'] == 'user_1':
if state['bucket'] == 'cars':
ans = 'Toyota, Audi, Mercedes'
elif state['bucket'] == 'animals':
ans = 'horse, cat'
elif state['user_secret_key'] == 'user_2':
if state['bucket'] == 'cars':
ans = 'Opel, Bugatti'
elif state['bucket'] == 'animals':
ans = 'bird, dog, fish'
return {'answer': ans}
prompt = ChatPromptTemplate.from_messages(
[('system', ('You are supposed to select a bucket based on the user'
' request by setting the JSON `{{"bucket": ...}}`.')),
('user', '{message}')])
supervisor = prompt | llm.with_structured_output(State, method="json_mode")
agent = RunnableLambda(get_user_buckets)
workflow = StateGraph(State)
workflow.add_node('supervisor', supervisor)
workflow.add_node('agent', agent)
workflow.add_edge('supervisor', 'agent')
workflow.set_entry_point('supervisor')
graph = workflow.compile()
graph.invoke({'message': 'Show me all cars in the bucket.',
'user_secret_key': 'user_1'}) Given that I'm using langsmith to record the traces, is there a neat way to hide the state variable Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
thoffmann-artidis
Oct 22, 2024
Replies: 1 comment
-
Solution: https://python.langchain.com/docs/how_to/runnable_runtime_secrets/ |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
thoffmann-artidis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution: https://python.langchain.com/docs/how_to/runnable_runtime_secrets/