Skip to content

improved prompting, fixed extract #25

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 2 commits into from
Mar 13, 2025

Conversation

miguelg719
Copy link
Contributor

@miguelg719 miguelg719 commented Mar 10, 2025

extract now works, refined prompting a bit. Other potential improvements:

  • using resources for async results taking a while
  • maybe include generalized prompts (MCP prompts) for common actions? (ie. click, enter...)
  • improve logs/return of extract:
    currently:
{
  `schema`: {
    `type`: `object`,
    `required`: [
      `topResults`
    ],
    `properties`: {
      `topResults`: {
        `type`: `array`,
        `items`: {
          `type`: `object`,
          `required`: [
            `title`,
            `url`
          ],
          `properties`: {
            `url`: {
              `type`: `string`,
              `description`: `The URL of the search result`
            },
            `title`: {
              `type`: `string`,
              `description`: `The title of the search result`
            }
          }
        }
      }
    }
  },
  `instruction`: `Extract the title and URL of the top 3 search results for browserbase`
}Extraction result: undefinedOperation logs:
[2025-03-10T20:21:55.141Z] [DEBUG] REQUEST: {
  "timestamp": "2025-03-10T20:21:55.141Z",
  "type": "ListResources",
  "params": {}
}
[2025-03-10T20:21:55.142Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-03-10T20:21:55.142Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-03-10T20:22:00.140Z] [DEBUG] REQUEST: {
  "timestamp": "2025-03-10T20:22:00.140Z",
  "type": "ListResources",
  "params": {}
}
[2025-03-10T20:22:00.140Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-03-10T20:22:00.140Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-03-10T20:22:05.148Z] [DEBUG] REQUEST: {
  "timestamp": "2025-03-10T20:22:05.148Z",
  "type": "ListResources",
  "params": {}
}
[2025-03-10T20:22:05.148Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-03-10T20:22:05.148Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-03-10T20:22:10.146Z] [DEBUG] REQUEST: {
  "timestamp": "2025-03-10T20:22:10.146Z",
  "type": "ListResources",
  "params": {}
}
[2025-03-10T20:22:10.147Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-03-10T20:22:10.147Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-03-10T20:22:15.140Z] [DEBUG] REQUEST: {
  "timestamp": "2025-03-10T20:22:15.140Z",
  "type": "ListResources",
  "params": {}
}
[2025-03-10T20:22:15.141Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-03-10T20:22:15.141Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-03-10T20:22:20.147Z] [DEBUG] REQUEST: {
  "timestamp": "2025-03-10T20:22:20.147Z",
  "type": "ListResources",
  "params": {}
}
[2025-03-10T20:22:20.148Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-03-10T20:22:20.147Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-03-10T20:22:25.141Z] [DEBUG] REQUEST: {
  "timestamp": "2025-03-10T20:22:25.141Z",
  "type": "ListResources",
  "params": {}
}
[2025-03-10T20:22:25.142Z] [DEBUG] RESPONSE: {
  "timestamp": "2025-03-10T20:22:25.142Z",
  "type": "ListResources",
  "response": {
    "resources": []
  }
}
[2025-03-10T20:22:29.786Z] [INFO] Extraction result: {"topResults":[{"title":"Browserbase","url":"https://www.browserbase.com"},{"title":"GitHub","url":"https://github.com/browserbase"},{"title":"GitHub","url":"https://github.com/browserbase/stagehand"}]}
Copy link
Collaborator

@filip-michalsky filip-michalsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we can merge on work on the other outstanding unchecked items

},
},
required: ["action"],
},
},
{
name: "stagehand_extract",
description: `Extracts structured data from the web page based on an instruction and a JSON schema.`,
description: `Extracts structured data from the web page based on an instruction and a JSON schema (Zod schema). Extract works best for extracting TEXT in a structured format.`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its absolutely crazy this prompt update made this work lol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right? are we good to merge?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miguelg719 yes good to merge this. I am now working on:

  • Using resources for async result loading. It seems that Claude, for example, makes the request to the MCP server and if it takes x amount of time it will try to continuously call the resources to get the updated result. This might fix timeout errors w/ inspector and other clients.
  • Test with cline. Here's a guide on how to test it and would be great to sync w/ Sophie once we integrate it as an MCP server to come up with use cases that can be advertised together. I think that the improvements will make Cline perform much better

will open a new PR!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, that's what I saw with claude! perfect

@@ -382,20 +391,13 @@ async function handleToolCall(
schema: zodSchema,
useTextExtract: true,
});
if (!data || typeof data !== "object" || !("data" in data)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filip-michalsky this was also causing an issue with extract

@miguelg719 miguelg719 merged commit 99cf01d into main Mar 13, 2025
@alexdphan alexdphan deleted the miguel/bb-997-improve-stagehand-mcp-prompting branch March 19, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants