-
Notifications
You must be signed in to change notification settings - Fork 189
Prototype dataset builder harness #8
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
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| .DS_Store | ||
| node_modules/ | ||
| backend/.npm-cache/ | ||
| .env | ||
| .env.local | ||
| Project_BigSet_brief.md | ||
| notion-docs.md | ||
| image.png | ||
| image-1.png | ||
| .omx/ | ||
| /car |
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,136 @@ | ||
| import type { | ||
| AgentHarnessStage, | ||
| DatasetBuildPlan, | ||
| DatasetColumnDefinition, | ||
| DatasetSourceStrategy, | ||
| } from "./types.js"; | ||
|
|
||
| export function createHarnessStages( | ||
| sourceStrategy: DatasetSourceStrategy, | ||
| hasMissingInputs: boolean | ||
| ): AgentHarnessStage[] { | ||
| const stages: AgentHarnessStage[] = []; | ||
|
|
||
| if (hasMissingInputs) { | ||
| stages.push({ | ||
| id: "clarify-missing-inputs", | ||
| title: "Ask for missing inputs", | ||
| purpose: | ||
| "Pause before scraping when the target sites need user-specific values.", | ||
| tool: "user_input", | ||
| canRunWithoutUser: false, | ||
| }); | ||
| } | ||
|
|
||
| stages.push( | ||
| { | ||
| id: "discover-source-candidates", | ||
| title: "Discover source candidates", | ||
| purpose: "Use TinyFish Search to find source pages likely to contain rows.", | ||
| tool: "tinyfish_search", | ||
| canRunWithoutUser: true, | ||
| }, | ||
| { | ||
| id: "fetch-source-pages", | ||
| title: "Fetch clean source content", | ||
| purpose: "Use TinyFish Fetch before browser automation for speed and cost.", | ||
| tool: "tinyfish_fetch", | ||
| canRunWithoutUser: true, | ||
| } | ||
| ); | ||
|
|
||
| if (sourceStrategy !== "search_fetch") { | ||
| stages.push({ | ||
| id: "browser-deep-extraction", | ||
| title: "Deep browser extraction", | ||
| purpose: | ||
| "Use TinyFish Agent or browser automation only when search/fetch cannot reach the value.", | ||
| tool: "tinyfish_agent", | ||
| canRunWithoutUser: !hasMissingInputs, | ||
| }); | ||
| } | ||
|
|
||
| stages.push( | ||
| { | ||
| id: "validate-cells", | ||
| title: "Validate extracted cells", | ||
| purpose: | ||
| "Reject rows that do not match schema, keep source URLs, and mark missing cells.", | ||
| tool: "validator", | ||
| canRunWithoutUser: true, | ||
| }, | ||
| { | ||
| id: "upsert-rows", | ||
| title: "Replace changed row values", | ||
| purpose: | ||
| "Use the identity column to replace current values instead of appending duplicates.", | ||
| tool: "database", | ||
| canRunWithoutUser: true, | ||
| } | ||
| ); | ||
|
|
||
| return stages; | ||
| } | ||
|
|
||
| export function createTinyFishAgentGoal(plan: DatasetBuildPlan): string { | ||
| const columnDescriptions = plan.schema.columns | ||
| .map((column) => `- ${column.name}: ${column.description}`) | ||
| .join("\n"); | ||
|
|
||
| return [ | ||
| `Build rows for dataset: ${plan.datasetName}.`, | ||
| `User request: ${plan.userRequest}`, | ||
| `Identity column: ${plan.schema.identityColumnName}`, | ||
| "Return only rows backed by source URLs.", | ||
| "Mark missing fields as null instead of guessing.", | ||
| "Columns:", | ||
| columnDescriptions, | ||
| ].join("\n"); | ||
| } | ||
|
|
||
| export function createTinyFishAgentOutputSchema(plan: DatasetBuildPlan) { | ||
| const rowProperties = Object.fromEntries( | ||
| plan.schema.columns.map((column) => [column.name, jsonSchemaForColumn(column)]) | ||
| ); | ||
|
|
||
| return { | ||
| type: "object", | ||
| additionalProperties: false, | ||
| required: ["rows", "sourceUrls", "validationIssues"], | ||
| properties: { | ||
| rows: { | ||
| type: "array", | ||
| items: { | ||
| type: "object", | ||
| additionalProperties: false, | ||
| required: [plan.schema.identityColumnName], | ||
| properties: rowProperties, | ||
| }, | ||
| }, | ||
| sourceUrls: { | ||
| type: "array", | ||
| items: { type: "string" }, | ||
| }, | ||
| validationIssues: { | ||
| type: "array", | ||
| items: { type: "string" }, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function jsonSchemaForColumn(column: DatasetColumnDefinition) { | ||
| if (column.kind === "number") { | ||
| return { type: ["number", "null"], description: column.description }; | ||
| } | ||
| if (column.kind === "boolean") { | ||
| return { type: ["boolean", "null"], description: column.description }; | ||
| } | ||
| if (column.kind === "json") { | ||
| return { | ||
| type: ["object", "array", "null"], | ||
| description: column.description, | ||
| }; | ||
| } | ||
| return { type: ["string", "null"], description: column.description }; | ||
| } | ||
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.
Output schema ignores
isRequiredcolumns.Rows currently require only the identity field, so required columns (for example
source_url) can be omitted and still pass schema validation.Proposed fix
export function createTinyFishAgentOutputSchema(plan: DatasetBuildPlan) { const rowProperties = Object.fromEntries( plan.schema.columns.map((column) => [column.name, jsonSchemaForColumn(column)]) ); + const requiredRowColumns = Array.from( + new Set([ + plan.schema.identityColumnName, + ...plan.schema.columns + .filter((column) => column.isRequired) + .map((column) => column.name), + ]) + ); return { @@ rows: { type: "array", items: { type: "object", additionalProperties: false, - required: [plan.schema.identityColumnName], + required: requiredRowColumns, properties: rowProperties, }, },📝 Committable suggestion
🤖 Prompt for AI Agents