Skip to content
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

feat: Add agent event if agentName in metadata #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shaw-matt
Copy link

@shaw-matt shaw-matt commented May 15, 2024

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

@shaw-matt shaw-matt marked this pull request as ready for review May 15, 2024 18:50
"agent",
"start",
user_id=user_id,
run_id=run_id_str,
Copy link
Author

@shaw-matt shaw-matt May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is this run_id will be the same as the regular 'llm' event that is tracked on the chat model start

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is a problem as it will break the traces. I'll see what I can do to avoid that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants