-
Notifications
You must be signed in to change notification settings - Fork 4
Add examples #3
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
Draft
parteeksingh24
wants to merge
15
commits into
main
Choose a base branch
from
add-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add examples #3
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
87ebaeb
Add Teams, Telegram examples
parteeksingh24 ca9b15e
Update examples
parteeksingh24 a7a002f
Tweaks
parteeksingh24 3fa9142
Add token validation and remove markdown parsing
parteeksingh24 53370cb
Update Slack example
parteeksingh24 a97aa26
Add LLM-as-a-judge and Streaming examples
parteeksingh24 4559f09
Add `env` language specifier in README files
parteeksingh24 011516d
Tweaks
parteeksingh24 ff8596d
Update streaming example
parteeksingh24 d43ef34
Tweaks
parteeksingh24 020c3da
Add Teams example
parteeksingh24 6911224
Update agents list
parteeksingh24 668682b
Update agents
parteeksingh24 c38173e
Tweaks
parteeksingh24 efddb5e
Update Gemini model
parteeksingh24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import type { AgentContext, AgentRequest, AgentResponse } from '@agentuity/sdk'; | ||
| import { openai } from '@ai-sdk/openai'; | ||
| import { generateObject } from 'ai'; | ||
| import { evaluationSchema, formatReport } from './story-eval'; | ||
|
|
||
| export default async function Agent( | ||
| req: AgentRequest, | ||
| resp: AgentResponse, | ||
| ctx: AgentContext | ||
| ) { | ||
| try { | ||
| // Get the prompt from request, or use a default | ||
| const prompt = | ||
| (await req.data.text()) || | ||
| 'Write a short story about an AI learning to paint'; | ||
|
|
||
| ctx.logger.info('Starting LLM-as-a-judge evaluation'); | ||
|
|
||
| // Get stories from gateway-provider | ||
| const gatewayAgent = await ctx.getAgent({ name: 'gateway-provider' }); | ||
| const stories = await gatewayAgent.run({ data: prompt }); | ||
| const storiesText = await stories.data.text(); | ||
|
|
||
| ctx.logger.debug('Received stories from gateway-provider'); | ||
|
|
||
| // Create evaluation prompt | ||
| const evaluationPrompt = ` | ||
| You are evaluating two AI-generated short stories. | ||
|
|
||
| Here are the stories: | ||
|
|
||
| ${storiesText} | ||
|
|
||
| Extract each story text: | ||
| - OpenAI story: appears after "### OpenAI (GPT-5 Nano)" | ||
| - Google story: appears after "### Google (Gemini 2.0 Flash)" | ||
|
|
||
| For each story, provide: | ||
| 1. Creativity score (1-10): How original and imaginative is it? | ||
| 2. Quality score (1-10): Overall writing quality | ||
| 3. Strengths: What works well (1-2 sentences) | ||
|
|
||
| Finally, provide a verdict declaring which story is better and why (2-3 sentences).`; | ||
|
|
||
| ctx.logger.info('Generating structured evaluation'); | ||
|
|
||
| // Generate structured evaluation | ||
| const evaluation = await generateObject({ | ||
| model: openai('gpt-5-nano'), | ||
| schema: evaluationSchema, | ||
| system: | ||
| 'You are a literary critic evaluating short AI-generated stories.', | ||
| prompt: evaluationPrompt, | ||
| }); | ||
|
|
||
| // Log key metrics | ||
| ctx.logger.debug('Evaluation scores', { | ||
| openai: evaluation.object.openai.quality, | ||
| google: evaluation.object.google.quality, | ||
| }); | ||
|
|
||
| // Return formatted report | ||
| return resp.markdown(formatReport(evaluation.object)); | ||
| } catch (error) { | ||
| ctx.logger.error('Error in LLM judge evaluation:', error); | ||
| return resp.text( | ||
| 'Sorry, there was an error running the evaluation. Please ensure the gateway-provider agent is available.' | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const welcome = () => { | ||
| return { | ||
| welcome: `Welcome to the <span style="color: light-dark(#0AA, #0FF);">LLM-as-a-Judge</span> example agent.\n\n### About\n\nThis agent demonstrates the LLM-as-a-judge pattern, where one AI model evaluates the outputs of other models. It generates content using the gateway-provider agent (which uses two different AI models), then evaluates both outputs with structured scoring and feedback.\n\n### Testing\n\nTry the default prompt about AI learning to paint, or send your own story prompt. The agent calls \`gateway-provider\` to generate two stories (one from each AI model), then provides an evaluation comparing their creativity, quality, and strengths.\n\n### Questions?\n\nThe "Help" command is not available for this agent, as it's a specific example demonstration.`, | ||
| prompts: [ | ||
| { | ||
| data: 'Write a short story about an AI learning to paint', | ||
| contentType: 'text/plain', | ||
| }, | ||
| ], | ||
| }; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify the model name and consider more robust parsing.
The implementation follows structured error handling guidelines and correctly integrates with the evaluation schema. However, there are two concerns:
Model name verification needed: Line 49 uses
openai('gpt-5-nano'), which doesn't match known OpenAI model naming conventions (typicallygpt-4,gpt-4-turbo,gpt-3.5-turbo, etc.). If this model doesn't exist, the agent will fail at runtime.Fragile format coupling: Lines 35-36 hardcode markdown section headers to extract stories from
gateway-provideroutput. If the upstream agent changes its output format, the evaluation prompt won't correctly identify the stories, leading to poor extraction results or evaluation failures.For issue 1, verify the correct model name:
For issue 2, consider adding format validation or using a more robust parsing approach:
// Get stories from gateway-provider const gatewayAgent = await ctx.getAgent({ name: 'gateway-provider' }); const stories = await gatewayAgent.run({ data: prompt }); const storiesText = await stories.data.text(); ctx.logger.debug('Received stories from gateway-provider'); + + // Validate expected format + if (!storiesText.includes('### OpenAI') || !storiesText.includes('### Google')) { + throw new Error('Unexpected format from gateway-provider agent'); + } // Create evaluation prompt🤖 Prompt for AI Agents