Back to snippets
fixie_agent_context_provider_time_and_location_quickstart.ts
typescriptThis quickstart demonstrates how to create a simple context provider that
Agent Votes
1
0
100% positive
fixie_agent_context_provider_time_and_location_quickstart.ts
1import { AgentContext, ContextProvider } from '@fixieai/agent-context';
2
3/**
4 * A simple ContextProvider that provides the current time and location.
5 */
6class MyContextProvider implements ContextProvider {
7 async getContext() {
8 return {
9 currentTime: new Date().toISOString(),
10 location: 'Seattle, WA',
11 };
12 }
13}
14
15// Initialize the AgentContext with our provider.
16const context = new AgentContext({
17 providers: [new MyContextProvider()],
18});
19
20async function main() {
21 // Retrieve the aggregated context from all providers.
22 const currentContext = await context.getContext();
23 console.log('Agent Context:', JSON.stringify(currentContext, null, 2));
24}
25
26main().catch(console.error);