Mohamed ATia
Mohamed ATia

Reputation: 21

Dynamically change langsmith project (LANGCHAIN_PROJECT value)

I have a graph that I use in 2 places in my API. (note that the graph has many nodes and edges)

  1. as an independent graph exposed through /my-api1

  2. as a subgraph, exposed through /my-api2

problem is, when calling through my-api1 i want to log to LangSmith project1
and when calling through my-api2 I want to log to LangSmith project2.

i cannot apply @traceable decorator because the same methods/nodes are used in 2 places.

is there another way to invoke my graph and instructing it to write so a specific langsmith project?

os.environ["LANGCHAIN_PROJECT"] = appConfig.langchain_project covers point 1.

I read about RunTrees, but i couldn't pass the config object as a parameter.

https://github.com/langchain-ai/langgraph/discussions/2381

config = {
"run_id": request.thread_id,
"recursion_limit": 150,
"configurable": {
    "thread_id": str(uuid.uuid4()),
    "checkpoint_ns": ""
   },
}

graph = graph_builder.get_graph()

rt = RunTree(
    run_type="chain",
    name="My Graph",
    inputs=state,
    project_name="project2"
    )

# how to pass graph and config values and get the result?

rt.end(outputs=???)
rt.postRun()

Upvotes: 2

Views: 74

Answers (1)

Mohamed ATia
Mohamed ATia

Reputation: 21

based on the answer i got from GitHub

import langsmith as ls

with ls.tracing_context(project="foo"):
    ...

Upvotes: 0

Related Questions