-
Notifications
You must be signed in to change notification settings - Fork 136
feat: add Lightcone integration with a Wikipedia search example and docs #270
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
Open
eddieogola
wants to merge
6
commits into
inngest:main
Choose a base branch
from
eddieogola:tzafon-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f177a4
feat: add Tzafon integration with a Wikipedia search example and corr…
eddieogola e567703
Merge branch 'main' into tzafon-integration
eddieogola ba6ffce
Merge branch 'main' into tzafon-integration
eddieogola 60e282f
Merge branch 'main' into tzafon-integration
eddieogola 72baa56
refactor: update Tzafon example to Lightcone SDK and Starlight docs
eddieogola 0128f8e
docs: add Lightcone to the docs sidebar
eddieogola 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,181 @@ | ||
| --- | ||
| title: Using AgentKit with Lightcone | ||
| description: "Develop AI Agents that can browse the web using Lightcone" | ||
| --- | ||
|
|
||
| import { Steps, Tabs, TabItem, LinkCard } from '@astrojs/starlight/components'; | ||
|
|
||
| [Lightcone](https://docs.lightcone.ai) (by [Tzafon](https://www.tzafon.ai)) provides managed cloud browsers and computers to enable Agents to browse the web autonomously. | ||
|
|
||
| ## Building AgentKit tools using Lightcone | ||
|
|
||
| Creating AgentKit [tools](/concepts/tools) using the Lightcone TypeScript SDK is straightforward. | ||
|
|
||
| <Steps> | ||
|
|
||
| 1. **Install AgentKit** | ||
|
|
||
| Within an existing project, install AgentKit, Lightcone and Playwright core: | ||
|
|
||
| <Tabs> | ||
| <TabItem label="npm"> | ||
| ```shell | ||
| npm install @inngest/agent-kit inngest @tzafon/lightcone playwright-core | ||
| ``` | ||
| </TabItem> | ||
| <TabItem label="pnpm"> | ||
| ```shell | ||
| pnpm install @inngest/agent-kit inngest @tzafon/lightcone playwright-core | ||
| ``` | ||
| </TabItem> | ||
| <TabItem label="yarn"> | ||
| ```shell | ||
| yarn add @inngest/agent-kit inngest @tzafon/lightcone playwright-core | ||
| ``` | ||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| <details> | ||
| <summary>Don't have an existing project?</summary> | ||
|
|
||
| To create a new project, create a new directory then initialize using your package manager: | ||
|
|
||
| <Tabs> | ||
| <TabItem label="npm"> | ||
| ```shell | ||
| mkdir my-agent-kit-project && npm init | ||
| ``` | ||
| </TabItem> | ||
| <TabItem label="pnpm"> | ||
| ```shell | ||
| mkdir my-agent-kit-project && pnpm init | ||
| ``` | ||
| </TabItem> | ||
| <TabItem label="yarn"> | ||
| ```shell | ||
| mkdir my-agent-kit-project && yarn init | ||
| ``` | ||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| </details> | ||
|
|
||
| 2. **Setup an AgentKit Network with an Agent** | ||
|
|
||
| Create an Agent and its associated Network, for example a Wikipedia Search Agent: | ||
|
|
||
| ```typescript | ||
| import { | ||
| openai, | ||
| createAgent, | ||
| createNetwork, | ||
| } from "@inngest/agent-kit"; | ||
|
|
||
| const searchAgent = createAgent({ | ||
| name: "wikipedia_searcher", | ||
| description: "An agent that searches Wikipedia for relevant information", | ||
| system: | ||
| "You are a helpful assistant that searches Wikipedia for relevant information.", | ||
| }); | ||
|
|
||
| // Create the network | ||
| const wikipediaSearchNetwork = createNetwork({ | ||
| name: "wikipedia_search_network", | ||
| description: "A network that searches Wikipedia using Lightcone", | ||
| agents: [searchAgent], | ||
| maxIter: 2, | ||
| defaultModel: openai({ | ||
| model: "gpt-4o-mini", | ||
| apiKey: process.env.OPENAI_API_KEY, | ||
| }), | ||
| }); | ||
| ``` | ||
|
|
||
| 3. **Create a Lightcone tool** | ||
|
|
||
| Let's configure the Lightcone SDK and create a tool that can search Wikipedia: | ||
|
|
||
| ```typescript {5, 8-9, 11-13} | ||
| import { | ||
| openai, | ||
| createAgent, | ||
| createNetwork, | ||
| createTool, | ||
| } from "@inngest/agent-kit"; | ||
| import { z } from "zod"; | ||
| import { chromium } from "playwright-core"; | ||
| import Lightcone from "@tzafon/lightcone"; | ||
|
|
||
| const client = new Lightcone({ | ||
| apiKey: process.env.LIGHTCONE_API_KEY as string, | ||
| }); | ||
|
|
||
| const BASE_URL = "https://api.tzafon.ai"; | ||
|
|
||
| // Create a tool to search Wikipedia using Lightcone | ||
| const searchWikipedia = createTool({ | ||
| name: "search_wikipedia", | ||
| description: "Search Wikipedia for relevant information", | ||
| parameters: z.object({ | ||
| query: z.string().describe("The search query for Wikipedia"), | ||
| }), | ||
| handler: async ({ query }, { step }) => { | ||
| return await step?.run("search-on-wikipedia", async () => { | ||
| // Spin up a cloud browser | ||
| const session = await client.computers.create({ kind: "browser" }); | ||
|
|
||
| // Build the CDP URL from the session endpoint and connect | ||
| const cdpUrl = `${BASE_URL}${session.endpoints?.cdp}`; | ||
| const browser = await chromium.connectOverCDP(cdpUrl, { | ||
| headers: { | ||
| Authorization: `Bearer ${process.env.LIGHTCONE_API_KEY}`, | ||
| }, | ||
| }); | ||
|
|
||
| try { | ||
| const page = browser.contexts()[0].pages()[0]; | ||
|
|
||
| await page.goto( | ||
| `https://en.wikipedia.org/w/index.php?search=${encodeURIComponent(query)}`, | ||
| { waitUntil: "domcontentloaded" }, | ||
| ); | ||
|
|
||
| // If we landed on a results page, open the first result | ||
| const firstResult = page | ||
| .locator("ul.mw-search-results li div.mw-search-result-heading a") | ||
| .first(); | ||
| if (await firstResult.count()) { | ||
| await firstResult.click(); | ||
| await page.waitForLoadState("domcontentloaded"); | ||
| } | ||
|
|
||
| const title = await page.title(); | ||
| const content = await page.innerText("#mw-content-text"); | ||
| return `${title}\n\n${content.slice(0, 4000)}`; | ||
| } finally { | ||
| await browser.close(); | ||
| await client.computers.delete(session.id!); | ||
| } | ||
| }); | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| :::note | ||
| Configure your `LIGHTCONE_API_KEY` in the `.env` file. You can find your API | ||
| key and setup instructions in the [Lightcone docs](https://docs.lightcone.ai). | ||
| ::: | ||
|
|
||
| :::tip | ||
| We recommend building tools using Lightcone with Inngest's `step.run()` function. This ensures that the tool will only run once across multiple runs. | ||
|
|
||
| More information about using `step.run()` can be found in the [Multi steps tools](/advanced-patterns/multi-steps-tools) page. | ||
| ::: | ||
|
|
||
| </Steps> | ||
|
|
||
| ### Example: Wikipedia Search Agent using Lightcone | ||
|
|
||
| You will find a complete example of a Wikipedia search agent using Lightcone in the Wikipedia Search Agent example: | ||
|
|
||
| <LinkCard title="Wikipedia Search Agent using Lightcone" href="https://github.com/inngest/agent-kit/tree/main/examples/wikipedia-search-tzafon#readme" description="This example shows how to build tools using Lightcone to power a Wikipedia search agent." /> | ||
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,2 @@ | ||
| OPENAI_API_KEY=your_openai_api_key # Get from https://platform.openai.com/api-keys | ||
| LIGHTCONE_API_KEY=your_lightcone_api_key # Get from https://docs.lightcone.ai |
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,80 @@ | ||
| # Wikipedia Search Agent with Lightcone and Agent Kit | ||
|
|
||
| This example demonstrates how to build an AI-powered Wikipedia search agent using AgentKit and [Lightcone](https://docs.lightcone.ai) (by Tzafon). The agent can search Wikipedia for information using natural language queries and return relevant results. | ||
|
|
||
| ## Features | ||
|
|
||
| - 🤖 AI-powered Wikipedia search using GPT-4o mini | ||
| - 🌐 Browser automation with Lightcone's managed cloud browsers | ||
| - 🔍 Semantic search capabilities | ||
| - ⚡️ Built with Inngest Agent Kit for robust agent orchestration | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js (v20 or later) | ||
| - A [Lightcone](https://docs.lightcone.ai) account and API key. You can find more information in the [docs](https://docs.lightcone.ai). | ||
| - An OpenAI API key | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Install dependencies: | ||
|
|
||
| ```bash | ||
| pnpm install | ||
| ``` | ||
|
|
||
| 2. Create a `.env` file in the project root with the following variables: | ||
|
|
||
| ```env | ||
| LIGHTCONE_API_KEY=your_lightcone_api_key | ||
| OPENAI_API_KEY=your_openai_api_key | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| The example consists of several key components: | ||
|
|
||
| 1. **Wikipedia Search Tool**: A custom tool built with Lightcone that searches Wikipedia using browser automation. | ||
|
|
||
| 2. **Search Agent**: An AI agent powered by GPT-4o mini that understands natural language queries and uses the Wikipedia search tool. | ||
|
|
||
| 3. **Agent Network**: A network configuration that orchestrates the agent's behavior and manages the conversation flow. | ||
|
|
||
| The agent uses Lightcone to: | ||
|
|
||
| - Create browser sessions | ||
| - Navigate to Wikipedia's search interface | ||
| - Perform searches | ||
| - Extract relevant information | ||
|
|
||
| ## Usage | ||
|
|
||
| 1. Start the server: | ||
|
|
||
| ```bash | ||
| pnpm dev | ||
| ``` | ||
|
|
||
| The server will start on port 3000. | ||
|
|
||
| 2. Start the Inngest Dev Server | ||
|
|
||
| ```bash | ||
| npx inngest-cli@latest dev | ||
| ``` | ||
|
|
||
| The Inngest Dev Server will start at [http://127.0.0.1:8288/](http://127.0.0.1:8288/). | ||
|
|
||
| 3. Trigger the function | ||
|
|
||
| Navigate to the Inngest Dev Server runs view: [http://127.0.0.1:8288/functions](http://127.0.0.1:8288/functions). | ||
|
|
||
| From there, trigger the `wikipedia_search_network` function with your query: | ||
|
|
||
| ```json | ||
| { | ||
| "data": { | ||
| "input": "Who won the super bowl in 2024?" | ||
| } | ||
| } | ||
| ``` |
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,23 @@ | ||
| { | ||
| "name": "wikipedia-search-tzafon", | ||
| "version": "1.0.0", | ||
| "description": "AgentKit + Lightcone Wikipedia search example", | ||
| "scripts": { | ||
| "dev": "tsx watch src/main.ts" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "MIT", | ||
| "packageManager": "pnpm@10.26.2", | ||
| "dependencies": { | ||
| "@inngest/agent-kit": "^0.13.2", | ||
| "@tzafon/lightcone": "^0.19.0", | ||
| "dotenv": "^17.2.3", | ||
| "playwright-core": "^1.57.0", | ||
| "zod": "^4.2.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^25.0.3", | ||
| "tsx": "^4.21.0" | ||
| } | ||
| } |
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.
Following the guide as written creates
searchWikipediain the next step but never adds it tosearchAgent, so the documented network has an agent with no tools and cannot actually browse Wikipedia via Lightcone. The complete example includestools: [searchWikipedia]; the integration guide should also instruct readers to add that property when defining or updating the agent.Useful? React with 👍 / 👎.