Skip to content

docs(tools): add Xquik examples#1456

Open
kriptoburak wants to merge 2 commits into
i-am-bee:mainfrom
kriptoburak:codex/add-xquik-tool-examples
Open

docs(tools): add Xquik examples#1456
kriptoburak wants to merge 2 commits into
i-am-bee:mainfrom
kriptoburak:codex/add-xquik-tool-examples

Conversation

@kriptoburak
Copy link
Copy Markdown

Which issue(s) does this pull-request address?

Closes: N/A

This is an examples-only addition for using a custom BeeAI tool with an authenticated external REST API.

Description

Adds Xquik search examples for both BeeAI Framework runtimes:

  • Python custom tool example at python/examples/tools/custom/xquik.py
  • TypeScript dynamic tool example at typescript/examples/tools/custom/xquik.ts
  • README links under each examples Tools section

The examples call GET /x/tweets/search with XQUIK_API_KEY, optional XQUIK_BASE_URL, and no new package dependencies.

Validation

  • python3.11 -m py_compile python/examples/tools/custom/xquik.py
  • ruff check --config python/pyproject.toml python/examples/tools/custom/xquik.py python/examples/README.md
  • prettier@3.6.2 --check typescript/examples/tools/custom/xquik.ts python/examples/README.md typescript/examples/README.md
  • esbuild@0.27.2 typescript/examples/tools/custom/xquik.ts --bundle --platform=node --format=esm '--external:beeai-framework/*' --external:zod
  • git diff --check

I could not run mise check, mise test:unit, or mise test:e2e locally because this checkout does not have the project's mise or yarn toolchain installed. The added examples were kept dependency-free and validated with focused syntax, formatting, and parse checks.

Checklist

General

Code quality checks

  • Code quality checks pass: mise check (mise fix to auto-fix)

Testing

  • Unit tests pass: mise test:unit
  • E2E tests pass: mise test:e2e
  • Tests are included (for bug fixes or new features)

Documentation

  • Documentation is updated
  • Embedme embeds code examples in docs. To update after edits, run: Python mise docs:fix

Signed-off-by: kriptoburak <kriptoburak@users.noreply.github.com>
@kriptoburak kriptoburak requested review from a team as code owners May 18, 2026 14:55
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 18, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation python Python related functionality typescript Typescript related functionality labels May 18, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the Xquik API tool for searching X posts, providing implementations in both Python and TypeScript. The Python implementation uses urllib and asyncio.to_thread to handle requests, while the TypeScript version utilizes DynamicTool and the fetch API. Review feedback suggests improving the robustness of UTF-8 decoding in the Python code to handle malformed data and guarding the execution logic in the TypeScript file to prevent side effects when the module is imported by other components.

Comment thread python/examples/tools/custom/xquik.py Outdated
)
try:
with urlopen(request, timeout=30) as response:
body = response.read().decode("utf-8")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The response body is decoded using utf-8 without error handling. If the API returns malformed UTF-8 or a different encoding, this will raise a UnicodeDecodeError. For better robustness and consistency with the error handling on line 36, consider using errors="replace".

Suggested change
body = response.read().decode("utf-8")
body = response.read().decode("utf-8", errors="replace")

Comment on lines +47 to +55
if (!process.env.XQUIK_API_KEY) {
console.log("Set XQUIK_API_KEY to run this example.");
} else {
const result = await xquikSearchTweetsTool.run({
query: "from:xquikcom",
limit: 5,
});
console.log(result.getTextContent());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The example execution logic at the end of the file runs immediately upon module import. Since xquikSearchTweetsTool is exported, this can cause unexpected side effects (such as network requests) if the tool is imported by other modules or tests. Consider guarding this block to ensure it only runs when the file is executed directly, similar to the if __name__ == "__main__": pattern used in the Python example.

Signed-off-by: kriptoburak <kriptoburak@users.noreply.github.com>
@kriptoburak
Copy link
Copy Markdown
Author

Addressed the review feedback in 6c6a2c989689d97b725006ad1d9e2852c70b80ee:

  • Python now decodes response bodies with UTF-8 replacement handling for malformed bytes.
  • TypeScript now guards the example runner with a direct-run check, so importing the module only exports the tool and has no console or network side effects.

Focused validation reran successfully: Python 3.11 compile, Ruff check, Prettier check, esbuild parse/bundle, git diff --check, and scoped public-safety scan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python Python related functionality size:L This PR changes 100-499 lines, ignoring generated files. typescript Typescript related functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant