Skip to content

Conversation

@zebp
Copy link
Member

@zebp zebp commented Apr 30, 2025

Adds a new observability property to Agents that receives events during the Agent's exeuction that can be used for configurable observability. The default observability implementation prints the events to console, but in the future this could be hooked up to a UI or some other observability tooling.

@zebp zebp requested review from Copilot and threepointone April 30, 2025 19:08
@changeset-bot
Copy link

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: 5aee5a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
hono-agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces basic observability instrumentation for Agents by adding an observability property that emits events during key operations.

  • Adds an Observability interface and default implementation (genericObservability) in a new observability module.
  • Integrates observability events into various Agent lifecycle methods (RPC calls, state updates, schedule events, connection, and destruction).
  • Updates the build script and augments AIChatAgent with chat message instrumentation.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
packages/agents/src/observability/index.ts Introduces the observability type definitions and default logger.
packages/agents/src/index.ts Integrates observability event emission throughout Agent methods.
packages/agents/src/ai-chat-agent.ts Adds chat message instrumentation and filters duplicate messages.
packages/agents/scripts/build.ts Includes the observability module in the build process.
Files not reviewed (1)
  • packages/agents/package.json: Language not supported
Comments suppressed due to low confidence (1)

packages/agents/src/ai-chat-agent.ts:241

  • [nitpick] Consider renaming '#messagesNotAlreadyInAgent' to a more descriptive name like '#filterNewMessages' to improve clarity.
#messagesNotAlreadyInAgent(messages: ChatMessage[]) {

return;
}

console.log(event);
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if we should keep this log as the default for non-local mode, there could be billing implications if the user has Workers Logs enabled ($0.30 per million logs) @threepointone what do you think?

Adds a new `observability` property to Agents that receives events during the Agent's exeuction that can be used for whatever. The default observability implementation prints the events to console, but in the future this could be hooked up to a UI or some other observability tooling.
@zebp zebp force-pushed the zeb/instrumentation branch from 9ff4c11 to 4057c34 Compare July 2, 2025 15:29
@whoiskatrin whoiskatrin requested a review from ghostwriternr July 7, 2025 21:01
@ghostwriternr ghostwriternr merged commit dc7a99c into main Jul 11, 2025
1 check passed
@ghostwriternr ghostwriternr deleted the zeb/instrumentation branch July 11, 2025 09:11
@threepointone threepointone mentioned this pull request Jul 11, 2025
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