Skip to content

feat: Introduce userContext for agent operations#71

Merged
omeraplak merged 8 commits intomainfrom
feat/user-context
Apr 30, 2025
Merged

feat: Introduce userContext for agent operations#71
omeraplak merged 8 commits intomainfrom
feat/user-context

Conversation

@omeraplak
Copy link
Copy Markdown
Member

This PR introduces the userContext feature to VoltAgent, providing a mechanism to pass custom, operation-specific data through the lifecycle of an agent execution (e.g., a single generateText call).

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

Previously, there was no clean, isolated way to share request-specific information (like tracing IDs, user configurations, temporary state) between agent lifecycle hooks (onStart, onEnd) and tool executions within the same operation without resorting to potentially unsafe or complex workarounds.

What is the new behavior?

This PR implements OperationContext, which includes:

  • A unique operationId.
  • A userContext: Map<string | symbol, unknown> property.

This OperationContext is now accessible within:

  • Agent hooks (onStart, onEnd).

  • Tool execute functions via the options parameter (options.operationContext).

  • @voltagent/core:

    • Added OperationContext type and integrated it into agent generation methods (generateText, streamText, etc.).
    • Passed OperationContext to hooks and tool execution contexts.
    • Implemented serializeValueForDebug utility (moved to src/utils/serialization.ts) to safely represent userContext (including complex types like functions, Symbols, classes) in history events.
    • Updated history event creation (createStandardTimelineEvent, addToolEvent) to include the serialized userContext.
    • Added unit tests for serializeValueForDebug.
  • console:

    • Updated ExecutionDrawer.tsx in the debug UI to display the userContext associated with the selected timeline event, using the JsonViewer.
  • website:

    • Added new documentation page docs/agents/context.md explaining the userContext feature with usage examples.
  • Utils:

    • Created packages/core/src/utils/serialization.ts for the serialization logic.

closes

Notes for reviewers

@omeraplak omeraplak changed the title feat: introduce userContext in OperationContext for custom data manag… feat: Introduce userContext for agent operations Apr 30, 2025
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 30, 2025

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: 38b3051
Status: ✅  Deploy successful!
Preview URL: https://fe690475.voltagent.pages.dev
Branch Preview URL: https://feat-user-context.voltagent.pages.dev

View logs

@omeraplak omeraplak merged commit 1f20509 into main Apr 30, 2025
5 checks passed
@omeraplak omeraplak deleted the feat/user-context branch April 30, 2025 19:04
codegen-sh Bot referenced this pull request in Zeeeepa/voltagent May 28, 2025
🎯 CONSOLIDATION OBJECTIVES ACHIEVED:
✅ Merged monitoring and performance systems into unified platform
✅ Consolidated alerting and analytics for consistency
✅ Unified observability components across all services
✅ Eliminated duplicate metrics collection
✅ Standardized monitoring interfaces

📊 CONSOLIDATED COMPONENTS:
- Performance monitoring system (PR #51)
- Analytics and metrics collection (PR #67)
- Real-time monitoring & performance analytics (PR #71)
- Comprehensive end-to-end workflow testing (PR #72)
- Consolidated monitoring & testing systems (PR VoltAgent#94)

🚀 NEW UNIFIED SYSTEM FEATURES:
- Single comprehensive monitoring system
- Unified performance analytics with real-time tracking
- Consolidated alerting system with rule-based alerts
- Integrated observability platform with OpenTelemetry
- Standardized monitoring interfaces across all components
- Zero duplication in monitoring logic
- Consistent metrics collection patterns
- Dashboard system for visualization
- Enhanced CLI analytics integration

🔧 TECHNICAL IMPLEMENTATION:
- Core monitoring orchestrator (CoreMonitor)
- Unified metrics collection (MetricsCollector)
- Consolidated analytics tracking (AnalyticsTracker)
- Performance monitoring (PerformanceMonitor)
- Rule-based alerting system (AlertingSystem)
- Dashboard and visualization (DashboardSystem)
- Agent integration helpers (AgentMonitoringIntegration)
- Enhanced OpenTelemetry integration
- CLI analytics consolidation
- Comprehensive configuration management
- Backward compatibility with existing systems

📈 BENEFITS:
- Single source of truth for all monitoring data
- Reduced complexity and maintenance overhead
- Improved performance through unified collection
- Better observability with correlated data
- Standardized monitoring patterns
- Enhanced debugging and troubleshooting capabilities
- Comprehensive testing and validation

🧪 TESTING & VALIDATION:
- Comprehensive test suite for all components
- Migration guide for existing implementations
- Backward compatibility validation
- Performance benchmarking
- Error handling and resilience testing

This consolidation eliminates redundancy across PRs #51,67,71,72,94
and provides a single, cohesive monitoring platform for VoltAgent.
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.

1 participant