Hi, I have been using excellent phoenix arize for LLM traces. Now, I have a single agent that acts as driver of multiple no-code agents. Default Langchain/Langgraph instrumentor registers a single trace provider project. If I need each of the no-code agent to be registered as a separate phoenix project, how can I achieve this ? Do I need to extend the Langchain instrumentor or some other way to customize it ? These no-code agents are dynamic and not known to the driver agent apriori for static configuration
To register each no-code agent as a separate Phoenix project, you can use the OpenInferenceTracer and LangChainInstrumentor to dynamically set the project name for each agent. You don't need to extend the LangChain instrumentor; instead, you can configure the tracer provider with different resource attributes for each agent. This can be done by setting the project name in the resource attributes of the tracer provider dynamically as each agent is instantiated.Here's a general approach: 1. Set Resource Attributes: Define the project name in the resource attributes for each agent dynamically.
2. Configure Tracer Provider: Use the TracerProvider to set up the trace provider with the specified resource attributes for each agent.
3. Instrument Each Agent: Use the LangChainInstrumentor to instrument each agent with its own tracer provider.Here's a code snippet to illustrate this: LBKSfrom phoenix.trace.langchain import OpenInferenceTracer, LangChainInstrumentor from opentelemetry.sdk.resources import Resource from opentelemetry.sdk import trace as trace_sdkLBKSdef setup_agent_tracer(agent_name): resource = Resource(attributes={"openinference.project.name": agent_name}) tracer_provider = trace_sdk.TracerProvider(resource=resource) tracer = OpenInferenceTracer(tracer_provider=tracer_provider) LangChainInstrumentor(tracer=tracer).instrument()LBKS# Example usage for each no-code agent agent_names = ["agent1", "agent2", "agent3"] # Dynamically determined for agent_name in agent_names: setup_agent_tracer(agent_name)LBKSThis setup ensures that each agent is registered under a separate project in Phoenix. Would you like more details on any specific part of this setup?Sources:
- GitHub Issue #3375
馃挕聽Hint: Mention RunLLM in the thread for followups.
That鈥檚 an interesting use case. Unfortunately, because those agents are child spans in the same trace tree, and because the current Phoenix database hierarchy can only organize spans into traces and then traces into projects, subtrees of the same trace cannot belong to different projects.
The LangChainInstrumentor.instrument() method can indeed be used multiple times, allowing you to instrument different parts of your application separately. By configuring the tracer provider with different resource attributes for each agent, you can effectively manage multiple projects within the same application. This flexibility allows you to dynamically assign different projects to different agents, even if they are part of the same trace tree.If you encounter any issues or need further assistance while implementing this, feel free to reach out. Would you like more detailed guidance on any specific aspect of this process?Sources:
- GitHub Issue #3375
馃挕聽Hint: Mention RunLLM in the thread for followups.
Getting back to this thread to update. Approach mentioned by RunLLM doesn't work, atleast not anymore. Opentelemetry libraries complain about multiple instrumentors and doesn't register.
WARNING:opentelemetry.instrumentation.instrumentor:Attempting to instrument while already instrumented
But the use_project approach mentioned in this issue https://github.com/Arize-ai/phoenix/issues/3375 works well.
It seems likely that the use_project approach mentioned in GitHub Issue #3375 is a more suitable solution for your use case. This approach allows you to switch projects dynamically within the same application context, which can be particularly useful when dealing with multiple agents that need to be registered under different projects.The warning you encountered about multiple instrumentors suggests that the OpenTelemetry libraries are detecting attempts to instrument the same component multiple times, which can lead to conflicts. The use_project context manager provides a cleaner way to manage project assignments without re-instrumenting components.If you need further assistance or have additional questions about implementing the use_project approach, feel free to ask. Would you like more details on how to effectively use this method?Sources:
- GitHub Issue #3375
馃挕聽Hint: Mention RunLLM in the thread for followups.
