Skip to content

Commit 67f51af

Browse files
committed
feat: Enhance image agent with additional runtime context properties
- Added 'aspectratio' and 'numberOfImages' to ImageRuntimeContext type. - Updated instructions in imageAgent to utilize aspect ratio and resolution from runtime context. - Configured image provider options to include aspect ratio and image size settings.
1 parent b15cf0a commit 67f51af

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/mastra/agents/image.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ import { RuntimeContext } from '@mastra/core/runtime-context'
44
import { imageGen, pgMemory } from '../config'
55
import { log } from '../config/logger'
66

7+
78
export type UserTier = 'free' | 'pro' | 'enterprise'
89
export type ImageRuntimeContext = {
910
'user-tier': UserTier
1011
language: 'en' | 'es' | 'ja' | 'fr'
12+
aspectratio: '16:9' | '4:3' | '1:1'
13+
resolution: '2K' | '1K'
14+
numberOfImages: 1 | 2 | 4
1115
}
1216

1317
log.info('Initializing Financial Chart Agents...')
1418

19+
const aspectRatio = '16:9';
20+
const AspectRatio2K = '4:3';
21+
const resolution = '2K';
22+
const resolution1K = '1K';
23+
1524
/**
1625
* Chart Type Advisor Agent
1726
* Recommends optimal chart types based on financial data characteristics
@@ -24,16 +33,23 @@ export const imageAgent = new Agent({
2433
// runtimeContext is read at invocation time
2534
const userTier = runtimeContext.get('user-tier') ?? 'free'
2635
const language = runtimeContext.get('language') ?? 'en'
36+
const aspectratioX = runtimeContext.get('aspectratio') ?? '16:9'
37+
const resolutionY = runtimeContext.get('resolution') ?? '2K'
2738
return {
2839
role: 'system',
2940
content: `You are an expert in generating images based on user requirements.
3041
tier: ${userTier}
3142
language: ${language}
43+
aspect ratio: ${aspectratioX}
44+
resolution: ${resolutionY}
3245
Your task is to create visually appealing and informative images that accurately represent the data provided by the user. Consider the user's preferences, such as color scheme and chart style, to ensure the image is both aesthetically pleasing and informative.`,
3346
providerOptions: {
3447
google: {
3548
numberOfImages: 4,
36-
49+
imageConfig: {
50+
aspectRatio: aspectRatio || AspectRatio2K,
51+
imageSize: resolution || resolution1K,
52+
},
3753
}
3854
}
3955
}

0 commit comments

Comments
 (0)