Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
59c4550
Adds native Live Search support to xAI provider
pawel-twardziak Dec 2, 2025
dfb4789
Merge branch 'main' into implement-native-live-search
pawel-twardziak Dec 2, 2025
ce5d98c
Remove redundant exports
pawel-twardziak Dec 3, 2025
fd97842
Merge remote-tracking branch 'pawel-twardziak/implement-native-live-s…
pawel-twardziak Dec 3, 2025
d98ca44
Merge branch 'main' into implement-native-live-search
pawel-twardziak Dec 3, 2025
bbe6a7b
Merge branch 'main' into implement-native-live-search
pawel-twardziak Dec 10, 2025
e95f0ec
feat(xai): Enables native Live Search with flexible sources
pawel-twardziak Dec 10, 2025
9f4c6eb
refactor(xai): Moves XAILiveSearchTool definition
pawel-twardziak Dec 10, 2025
e5b0bd6
Merge branch 'main' into implement-native-live-search
pawel-twardziak Dec 10, 2025
9905ac7
chore(xai): Adds usage example for `xaiLiveSearch` tool
pawel-twardziak Dec 10, 2025
7d8abbc
refactor(xai): Exports tools via a dedicated module
pawel-twardziak Dec 11, 2025
de967b7
refactor(xai): Simplifies xAI live search tool options
pawel-twardziak Dec 11, 2025
8c9c789
Merge branch 'main' into implement-native-live-search
pawel-twardziak Dec 11, 2025
81b85ab
refactor(xai): Refactors xAI live search tool
pawel-twardziak Dec 11, 2025
bcf66b6
refactor(xai): Simplifies XAI Live Search tool definition
pawel-twardziak Dec 11, 2025
1abee53
chore(xai): Deprecates live search tool type
pawel-twardziak Dec 11, 2025
a26a2d7
chore(xai): Updates live search example in README
pawel-twardziak Dec 11, 2025
387aa23
chore(xai): Simplifies XAI Live Search tool usage
pawel-twardziak Dec 11, 2025
8044cb4
chore(xai): Clarifies xAI Live Search tool options casing
pawel-twardziak Dec 11, 2025
9a91495
refactor(xai): Standardizes XAI live search tool type
pawel-twardziak Dec 11, 2025
a5dc397
Update version to minor and add Live Search support
christian-bromann Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions libs/providers/langchain-xai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,86 @@ const message = new HumanMessage("What color is the sky?");
const res = await model.invoke([message]);
```

## Server Tool Calling (Live Search)

xAI supports server-side tools that are executed by the API rather than requiring client-side execution. The `live_search` tool enables the model to search the web for real-time information.

### Using the built-in live_search tool

```typescript
import { ChatXAI } from "@langchain/xai";

const model = new ChatXAI({
model: "grok-2-1212",
});

// Bind the live_search tool
const modelWithSearch = model.bindTools([{ type: "live_search" }]);
Comment thread
pawel-twardziak marked this conversation as resolved.
Outdated

// The model will search the web for real-time information
const result = await modelWithSearch.invoke(
"What happened in tech news today?"
);
console.log(result.content);
```

### Using searchParameters for more control

```typescript
import { ChatXAI } from "@langchain/xai";

const model = new ChatXAI({
model: "grok-2-1212",
searchParameters: {
mode: "auto", // "auto" | "on" | "off"
max_search_results: 5,
from_date: "2024-01-01", // ISO date string
return_citations: true,
},
});

const result = await model.invoke("What are the latest AI developments?");
```

### Override search parameters per request

```typescript
const result = await model.invoke("Find recent news about SpaceX", {
searchParameters: {
mode: "on",
max_search_results: 10,
allowed_domains: ["spacex.com", "nasa.gov"],
},
});
```

### Combining live_search with custom tools

```typescript
import { ChatXAI } from "@langchain/xai";

const model = new ChatXAI({ model: "grok-2-1212" });

const modelWithTools = model.bindTools([
{ type: "live_search" }, // Built-in server tool
Comment thread
pawel-twardziak marked this conversation as resolved.
Outdated
{
// Custom function tool
type: "function",
function: {
name: "get_stock_price",
description: "Get the current stock price",
parameters: {
type: "object",
properties: {
symbol: { type: "string" },
},
required: ["symbol"],
},
},
},
]);
```

## Development

To develop the `@langchain/xai` package, you'll need to follow these instructions:
Expand Down
Loading