lunary-ai / lunary-py

Lunary AI Python Client (Analytics, monitoring and evaluations for GenAI apps)
https://lunary.ai/docs/py
19 stars 15 forks source link

feat: Add agent event if agentName in metadata #44

Open shaw-matt opened 3 months ago

shaw-matt commented 3 months ago

In our implementation where we orchestrate agents with LangGraph and stream chunks async, there is no place where it makes sense to add an Agent decorator, mostly because we are streaming the chunks async.

It makes more sense to pass the agent name in the metadata when the tools are bound to an agent so that each invocation contains the metadata, i.e.

model_with_tools = self._model.bind_tools(self._tools).with_config(RunnableConfig(metadata={"agentName": self._agent_name}))

...

response = model_with_tools.invoke([*messages])

but this means the metadata is only available on_chat_model_start. So here I added a check to see if that metadata is present, and add an additional event to denote that an agent started an action