Skip to content

add TwelveLabs video understanding and embedding tool - #254

Open
mohit-twelvelabs wants to merge 2 commits into
om-ai-lab:mainfrom
mohit-twelvelabs:feat/twelvelabs-integration
Open

add TwelveLabs video understanding and embedding tool#254
mohit-twelvelabs wants to merge 2 commits into
om-ai-lab:mainfrom
mohit-twelvelabs:feat/twelvelabs-integration

Conversation

@mohit-twelvelabs

@mohit-twelvelabs mohit-twelvelabs commented Jun 24, 2026

Copy link
Copy Markdown

Hi! I'm Mohit, I work at TwelveLabs (@mohit-twelvelabs).

What this adds

A new opt-in agent tool, TwelveLabsVideo, that gives OmAgent's multimodal agents access to the TwelveLabs video AI models:

  • Pegasus (task: "analyze") — video understanding. Answer a natural language prompt about a video by URL (summarize, list objects, describe events, etc.).
  • Marengo (task: "embed") — multimodal embeddings. Produce a 512-dim embedding vector from text or an image, in a shared text/image/video embedding space (useful for video retrieval).

It follows the existing tool convention exactly (@registry.register_tool() on a BaseTool subclass with an ARGSCHEMA, mirroring TavilyWebSearch), so it is auto-discovered by registry.import_module() and usable from any tool config.

Why it helps

OmAgent already targets multimodal/video agents. This lets an agent reason about videos by URL without standing up a local video model — the heavy lifting runs server-side at TwelveLabs.

Opt-in / non-breaking

Nothing is wired into defaults. The tool only activates when added to a tool config and given an API key:

tools:
    - name: TwelveLabsVideo
      api_key: ${env|twelvelabs_api_key, null}

The twelvelabs SDK import is lazy (inside __init__), so it is only required when the tool is actually instantiated.

How it was tested

  • A focused test verifies registration, API-key validation, task dispatch, and required-argument guards.
  • Live smoke test against the real API: a Marengo embed call returns a 512-dim vector. The Pegasus analyze request wiring was verified end-to-end (the request reaches and is validated by the backend, which then fetches the video server-side).
  • SDK pinned to twelvelabs ^1.2.8 in omagent-core/pyproject.toml; docs added at docs/concepts/tool_system/twelvelabs_video.md mirroring the Tavily tool doc.

You can grab a free API key at https://twelvelabs.io — there's a generous free tier.

Summary by CodeRabbit

  • New Features
    • Added a TwelveLabsVideo tool that supports natural-language video analysis and multimodal embedding generation.
    • Supports both analysis and embedding flows with configurable model options and per-task inputs.
  • Documentation
    • Added a new documentation page covering TwelveLabsVideo tool capabilities, configuration (including API key setup), supported parameters, outputs, and a Python quick-start example.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9635c407-b463-433a-bea8-fc822f8469cd

📥 Commits

Reviewing files that changed from the base of the PR and between 9273066 and 695523b.

📒 Files selected for processing (2)
  • docs/concepts/tool_system/twelvelabs_video.md
  • omagent-core/src/omagent_core/tool_system/tools/twelvelabs_video/twelvelabs_video.py
✅ Files skipped from review due to trivial changes (1)
  • docs/concepts/tool_system/twelvelabs_video.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • omagent-core/src/omagent_core/tool_system/tools/twelvelabs_video/twelvelabs_video.py

Walkthrough

A new TwelveLabsVideo tool is added for analyze and embed tasks, with client initialization, task dispatch, validation, and error handling. The twelvelabs dependency is added, and a new concept page documents setup, inputs, outputs, and usage.

Changes

TwelveLabs Video Tool

Layer / File(s) Summary
Tool schema and execution
omagent-core/pyproject.toml, omagent-core/src/omagent_core/tool_system/tools/twelvelabs_video/twelvelabs_video.py
ARGSCHEMA defines the task enum and inputs. TwelveLabsVideo validates api_key, initializes the TwelveLabs client, dispatches run to _analyze or _embed, and returns task-specific results or error-shaped outputs. The twelvelabs ^1.2.8 dependency is added to pyproject.toml.
Concept page and usage examples
docs/concepts/tool_system/twelvelabs_video.md
Documents the tool purpose, configuration, API key setup, supported parameters, expected outputs for both tasks, and a Python example calling run for analyze and embed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through videos, nibble and bright,
Pegasus and Marengo now twinkle just right.
A tool for the warren, with embeddings in view,
I whisper “analyze” and “embed” anew.
Hoppy docs and code make the meadow sing!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a new TwelveLabs video understanding and embedding tool.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/concepts/tool_system/twelvelabs_video.md`:
- Around line 79-93: The quickstart examples for TwelveLabsVideo are incorrectly
using the protected _run() method instead of the public run() method provided by
BaseTool. Replace both calls to tool._run() (the Marengo embedding example and
the Pegasus video understanding example) with tool.run() and convert the keyword
arguments into a dictionary passed as the input parameter, ensuring all task
parameters like task, text, video_url, and prompt are properly formatted as
dictionary keys and values.

In
`@omagent-core/src/omagent_core/tool_system/tools/twelvelabs_video/twelvelabs_video.py`:
- Around line 134-147: The embed method in the twelvelabs_video class currently
accepts both text and image_url parameters but silently prioritizes text when
both are provided, creating ambiguous behavior. After the existing validation
check that ensures at least one of text or image_url is provided, add an
additional validation to reject the case where both parameters are provided
simultaneously. Raise a ValueError with a clear message indicating that exactly
one of text or image_url must be provided (not both).
- Around line 74-85: The api_key field in the class has a default value of None,
which bypasses the Pydantic v2 validator when the field is omitted during
instantiation. Remove the default value assignment (= None) from the api_key
field definition to make it required, changing it from Optional[str] = None to
just str. This ensures the api_key_validator will execute and fail at
construction time when the API key is not provided, rather than deferring the
failure to runtime.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 64da1db1-0ec2-4a6d-b4e7-6cf9d4076b73

📥 Commits

Reviewing files that changed from the base of the PR and between c131f82 and 9273066.

📒 Files selected for processing (4)
  • docs/concepts/tool_system/twelvelabs_video.md
  • omagent-core/pyproject.toml
  • omagent-core/src/omagent_core/tool_system/tools/twelvelabs_video/__init__.py
  • omagent-core/src/omagent_core/tool_system/tools/twelvelabs_video/twelvelabs_video.py

Comment thread docs/concepts/tool_system/twelvelabs_video.md Outdated
…blic run() in docs

- Make api_key a required field so the validator runs at construction
  instead of being bypassed for the default and deferring failure to runtime.
- Reject embed calls that supply both text and image_url for deterministic behavior.
- Update quickstart docs to call the public run({...}) API instead of _run().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant