-
Notifications
You must be signed in to change notification settings - Fork 155
Add update dataset workflow with refresh agents and shimmer UI #104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,74 @@ | ||
| import { Agent } from "@mastra/core/agent"; | ||
| import { createOpenRouter } from "@openrouter/ai-sdk-provider"; | ||
| import { buildPopulateTools } from "../tools/dataset-tools.js"; | ||
| import { searchWebTool, fetchPageTool } from "../tools/web-tools.js"; | ||
| import type { AuthContext } from "../workflows/populate.js"; | ||
| import type { PopulateColumn } from "../../pipeline/populate.js"; | ||
|
|
||
| const openrouter = createOpenRouter({ | ||
| apiKey: process.env.OPENROUTER_API_KEY!, | ||
| }); | ||
|
|
||
| function buildRefreshInstructions(columns: PopulateColumn[]): string { | ||
| const columnNames = columns.map((c) => c.name); | ||
| const columnsDesc = columns | ||
| .map( | ||
| (c) => | ||
| `- "${c.name}" (${c.type})${c.isPrimaryKey ? " [PRIMARY KEY]" : ""}${c.description ? `: ${c.description}` : ""}`, | ||
| ) | ||
| .join("\n"); | ||
|
|
||
| return `You are refreshing data for one existing row. Be fast — you have very few steps. | ||
|
|
||
| Columns: | ||
| ${columnsDesc} | ||
|
|
||
| RULES: | ||
| - You have at most 6 tool calls total. | ||
| - Start by following the steps in the "Previously found via" section — it describes exactly how the data was originally extracted (which URLs to fetch, which fields to look for). Reproduce those steps to get fresh data. | ||
| - If no "Previously found via" steps are provided, fall back to fetching the source URLs directly. | ||
| - If a source returns a 404, timeout, or is blocked, note it and move to the next. | ||
| - Compare the fetched data with the existing row data carefully. | ||
| - If data has MEANINGFULLY changed (not just formatting differences), call update_row with the FULL updated data object (all columns, not just changed ones), plus updated sources, row_summary, and how_found. | ||
| - If NO sources work (all 404/blocked), try ONE web search using the primary key values to find a current source. | ||
| - If the data is unchanged, do NOT call update_row. Just report your findings. | ||
| - Never fabricate values. If you can't verify a field, keep the existing value. | ||
|
|
||
| TOOL CALL FORMAT — every tool call argument must be a JSON object wrapped in curly braces: | ||
| fetch_page: {"url": "https://example.com"} | ||
| search_web: {"query": "your search terms"} | ||
| update_row: {"rowId": "<id>", "data": {${columnNames.map((n) => `"${n}": "value"`).join(", ")}}, "sources": ["https://..."], "row_summary": "one line about this entity", "how_found": "how you verified this data"} | ||
|
|
||
| WORKFLOW: | ||
| 1. Fetch the provided source URLs (1-2 calls). | ||
| 2. Compare fetched data with existing row data. | ||
| 3. If changed: call update_row with the full updated data. | ||
| If sources broken: try ONE search using primary key values, then fetch the best result. | ||
| 4. Write your final response: | ||
| UPDATED: true/false | ||
| CHANGES: what changed (or "no changes") | ||
| REASON: why you updated or didn't | ||
| `; | ||
| } | ||
|
|
||
| export function buildRefreshAgent( | ||
| authorizedDatasetId: string, | ||
| authContext: AuthContext, | ||
| columns: PopulateColumn[], | ||
| ): Agent { | ||
| const { update_row } = buildPopulateTools( | ||
| authorizedDatasetId, | ||
| authContext, | ||
| ); | ||
| return new Agent({ | ||
| id: "refresh-agent", | ||
| name: "Dataset Refresh Agent", | ||
| instructions: buildRefreshInstructions(columns), | ||
| model: openrouter("qwen/qwen3.7-max"), | ||
| tools: { | ||
| update_row, | ||
| search_web: searchWebTool, | ||
| fetch_page: fetchPageTool, | ||
| }, | ||
| }); | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.