Lorsque vous générez des réponses avec un modèle ou créez des agents, vous pouvez étendre leurs capacités grâce aux outils intégrés, à l’appel de fonction, à l’appel d’outils par programmation, à la recherche d’outils et aux serveurs MCP distants. Ces outils permettent au modèle de rechercher sur le web, de récupérer des informations dans vos fichiers, de charger des définitions d’outils à la demande pendant l’exécution, d’appeler vos propres fonctions, de combiner des appels d’outils en JavaScript ou d’accéder à des services tiers. Seuls gpt-5.4 et les modèles ultérieurs prennent en charge tool_search.
Choisissez l’intégration adaptée à votre environnement d’exécution : configurez les outils dans les requêtes de l’API Responses , dans les agents de l’API Agents ou dans les définitions du SDK Agents . La disponibilité des outils, leur configuration et la gestion des appels dépendent de l’intégration. Les exemples ci-dessous utilisent l’API Responses.
Recherche web Recherche de fichiers Recherche d’outils Appel de fonction MCP à distance Recherche web
1
2
3
4
5
6
7
8
9
10 import OpenAI from "openai" ;
const client = new OpenAI ();
const response = await client.responses. create ({
model: "gpt-6-astra" ,
tools: [{ type: "web_search" }],
input: "What was a positive news story from today?" ,
});
console. log (response.output_text); 1
2
3
4
5
6
7
8
9
10
11 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
tools=[{"type": "web_search"}],
input="What was a positive news story from today?",
)
print(response.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{
responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch),
},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What was a positive news story from today?")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.WebSearchTool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("What was a positive news story from today?")
.addTool(WebSearchTool.builder().type(WebSearchTool.Type.WEB_SEARCH).build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(ResponseTool.CreateWebSearchTool());
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("What was a positive news story from today?")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11 require "openai"
openai = OpenAI::Client.new
response = openai.responses.create(
model: "gpt-6-astra",
tools: [{ type: "web_search" }],
input: "What was a positive news story from today?"
)
puts(response.output_text) 1
2
3
4
5
6
7
8 curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"tools": [{"type": "web_search"}],
"input": "what was a positive news story from today?"
}' 1
2
3
4
5
6
7
8 openai responses create \
--model gpt-6-astra \
--raw-output \
--transform 'output.#(type=="message").content.0.text' <<'YAML'
tools:
- type: web_search
input: What was a positive news story from today?
YAML Recherche de fichiers
1
2
3
4
5
6
7
8
9
10
11
12
13
14 import OpenAI from "openai" ;
const openai = new OpenAI ();
const response = await openai.responses. create ({
model: "gpt-6-astra" ,
input: "What is deep research by OpenAI?" ,
tools: [
{
type: "file_search" ,
vector_store_ids: [ "<vector_store_id>" ],
},
],
});
console. log (response); 1
2
3
4
5
6
7
8
9
10 from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-astra",
input="What is deep research by OpenAI?",
tools=[{"type": "file_search", "vector_store_ids": ["<vector_store_id>"]}],
)
print(response) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is deep research by OpenAI?")},
Tools: []responses.ToolUnionParam{responses.ToolParamOfFileSearch([]string{"<vector_store_id>"})},
})
if err != nil {
panic(err)
}
fmt.Println(response)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import java.util.List;
String vectorStoreId = "<vector_store_id>";
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("What is deep research by OpenAI?")
.addFileSearchTool(List.of(vectorStoreId))
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
string vectorStoreId = "<vector_store_id>";
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateFileSearchTool([vectorStoreId])
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("What is deep research by OpenAI?")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 require "openai"
openai = OpenAI::Client.new
response = openai.responses.create(
model: "gpt-6-astra",
input: "What is deep research by OpenAI?",
tools: [
{
type: "file_search",
vector_store_ids: ["<vector_store_id>"]
}
]
)
puts(response) Recherche d’outils
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 import OpenAI from "openai" ;
const client = new OpenAI ();
const crmNamespace = {
type: "namespace" ,
name: "crm" ,
description: "CRM tools for customer lookup and order management." ,
tools: [
{
type: "function" ,
name: "get_customer_profile" ,
description: "Fetch a customer profile by customer ID." ,
parameters: {
type: "object" ,
properties: {
customer_id: { type: "string" },
},
required: [ "customer_id" ],
additionalProperties: false ,
},
},
{
type: "function" ,
name: "list_open_orders" ,
description: "List open orders for a customer ID." ,
defer_loading: true ,
parameters: {
type: "object" ,
properties: {
customer_id: { type: "string" },
},
required: [ "customer_id" ],
additionalProperties: false ,
},
},
],
};
const response = await client.responses. create ({
model: "gpt-6-astra" ,
input: "List open orders for customer CUST-12345." ,
tools: [crmNamespace, { type: "tool_search" }],
parallel_tool_calls: false ,
});
console. log (response.output); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 from openai import OpenAI
client = OpenAI()
crm_namespace = {
"type": "namespace",
"name": "crm",
"description": "CRM tools for customer lookup and order management.",
"tools": [
{
"type": "function",
"name": "get_customer_profile",
"description": "Fetch a customer profile by customer ID.",
"parameters": {
"type": "object",
"properties": {
"customer_id": {"type": "string"},
},
"required": ["customer_id"],
"additionalProperties": False,
},
},
{
"type": "function",
"name": "list_open_orders",
"description": "List open orders for a customer ID.",
"defer_loading": True,
"parameters": {
"type": "object",
"properties": {
"customer_id": {"type": "string"},
},
"required": ["customer_id"],
"additionalProperties": False,
},
},
],
}
response = client.responses.create(
model="gpt-6-astra",
input="List open orders for customer CUST-12345.",
tools=[
crm_namespace,
{"type": "tool_search"},
],
parallel_tool_calls=False,
)
print(response.output) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
parameters := map[string]any{
"type": "object",
"properties": map[string]any{"customer_id": map[string]any{"type": "string"}},
"required": []string{"customer_id"},
"additionalProperties": false,
}
namespace := responses.ToolParamOfNamespace(
"CRM tools for customer lookup and order management.",
"crm",
[]responses.NamespaceToolToolUnionParam{
{OfFunction: &responses.NamespaceToolToolFunctionParam{
Name: "get_customer_profile", Description: openai.String("Fetch a customer profile by customer ID."), Parameters: parameters,
}},
{OfFunction: &responses.NamespaceToolToolFunctionParam{
Name: "list_open_orders", Description: openai.String("List open orders for a customer ID."), DeferLoading: openai.Bool(true), Parameters: parameters,
}},
},
)
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("List open orders for customer CUST-12345.")},
Tools: []responses.ToolUnionParam{namespace, {OfToolSearch: &responses.ToolSearchToolParam{}}},
ParallelToolCalls: openai.Bool(false),
})
if err != nil {
panic(err)
}
fmt.Println(response.Output)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.responses.NamespaceTool;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.ToolSearchTool;
import java.util.List;
import java.util.Map;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("List open orders for customer CUST-12345.")
.parallelToolCalls(false)
.addTool(
NamespaceTool.builder()
.name("crm")
.description("CRM tools for customer lookup and order management.")
.addTool(
NamespaceTool.Tool.Function.builder()
.name("get_customer_profile")
.description("Fetch a customer profile by customer ID.")
.strict(true)
.parameters(
JsonValue.from(
Map.of(
"type",
"object",
"properties",
Map.of("customer_id", Map.of("type", "string")),
"required",
List.of("customer_id"),
"additionalProperties",
false)))
.build())
.addTool(
NamespaceTool.Tool.Function.builder()
.name("list_open_orders")
.description("List open orders for a customer ID.")
.deferLoading(true)
.strict(true)
.parameters(
JsonValue.from(
Map.of(
"type",
"object",
"properties",
Map.of("customer_id", Map.of("type", "string")),
"required",
List.of("customer_id"),
"additionalProperties",
false)))
.build())
.build())
.addTool(ToolSearchTool.builder().execution(ToolSearchTool.Execution.SERVER).build())
.build();
client.responses().create(params).output().forEach(System.out::println); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 require "openai"
client = OpenAI::Client.new
parameters = {
type: :object,
properties: { customer_id: { type: :string } },
required: ["customer_id"],
additionalProperties: false
}
response = client.responses.create(
model: "gpt-6-astra",
input: "List open orders for customer CUST-12345.",
parallel_tool_calls: false,
tools: [
{
type: :namespace,
name: "crm",
description: "CRM tools for customer lookup and order management.",
tools: [
{
type: :function,
name: "get_customer_profile",
description: "Fetch a customer profile by customer ID.",
parameters: parameters
},
{
type: :function,
name: "list_open_orders",
description: "List open orders for a customer ID.",
defer_loading: true,
parameters: parameters
}
]
},
{ type: :tool_search }
]
)
puts(response.output) Appel de fonction
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 import OpenAI from "openai" ;
const client = new OpenAI ();
const tools = [
{
type: "function" ,
name: "get_weather" ,
description: "Get current temperature for a given location." ,
parameters: {
type: "object" ,
properties: {
location: {
type: "string" ,
description: "City and country e.g. Bogotá, Colombia" ,
},
},
required: [ "location" ],
additionalProperties: false ,
},
strict: true ,
},
];
const response = await client.responses. create ({
model: "gpt-6-astra" ,
input: [
{ role: "user" , content: "What is the weather like in Paris today?" },
],
tools,
});
console. log (response.output[ 0 ]); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 from openai import OpenAI
client = OpenAI()
tools = [
{
"type": "function",
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia",
}
},
"required": ["location"],
"additionalProperties": False,
},
"strict": True,
},
]
response = client.responses.create(
model="gpt-6-astra",
input=[
{"role": "user", "content": "What is the weather like in Paris today?"},
],
tools=tools,
)
print(response.output[0].to_json()) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
parameters := map[string]any{
"type": "object",
"properties": map[string]any{
"location": map[string]any{
"type": "string",
"description": "City and country e.g. Bogotá, Colombia",
},
},
"required": []string{"location"},
"additionalProperties": false,
}
tool := responses.ToolParamOfFunction("get_weather", parameters, true)
tool.OfFunction.Description = openai.String("Get current temperature for a given location.")
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{
responses.ResponseInputItemParamOfMessage("What is the weather like in Paris today?", responses.EasyInputMessageRoleUser),
}},
Tools: []responses.ToolUnionParam{tool},
})
if err != nil {
panic(err)
}
fmt.Println(response.Output)
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.responses.FunctionTool;
import com.openai.models.responses.ResponseCreateParams;
import java.util.List;
import java.util.Map;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("What is the weather like in Paris today?")
.addTool(
FunctionTool.builder()
.name("get_weather")
.description("Get current temperature for a given location.")
.parameters(
FunctionTool.Parameters.builder()
.putAdditionalProperty("type", JsonValue.from("object"))
.putAdditionalProperty(
"properties",
JsonValue.from(
Map.of(
"location",
Map.of(
"type", "string",
"description",
"City and country e.g. Bogotá, Colombia"))))
.putAdditionalProperty("required", JsonValue.from(List.of("location")))
.putAdditionalProperty("additionalProperties", JsonValue.from(false))
.build())
.strict(true)
.build())
.build();
client.responses().create(params).output().forEach(System.out::println); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateFunctionTool(
functionName: "get_weather",
functionDescription: "Get current temperature for a given location.",
functionParameters: BinaryData.FromString(
"""
{
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
}
},
"required": ["location"],
"additionalProperties": false
}
"""
),
strictModeEnabled: true
)
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("What is the weather like in Paris today?")
);
ResponseResult response = await client.CreateResponseAsync(options);
foreach (ResponseItem outputItem in response.OutputItems)
{
if (outputItem is FunctionCallResponseItem functionCall)
{
Console.WriteLine(
$"{functionCall.FunctionName}({functionCall.FunctionArguments})"
);
}
else if (outputItem is MessageResponseItem message)
{
foreach (ResponseContentPart content in message.Content)
{
if (content.Kind == ResponseContentPartKind.OutputText)
{
Console.WriteLine(content.Text);
}
else if (content.Kind == ResponseContentPartKind.Refusal)
{
Console.WriteLine(content.Refusal);
}
}
}
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 require "openai"
openai = OpenAI::Client.new
tools = [
{
type: "function",
name: "get_weather",
description: "Get current temperature for a given location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "City and country e.g. Bogotá, Colombia"
}
},
required: ["location"],
additionalProperties: false
},
strict: true
}
]
response = openai.responses.create(
model: "gpt-6-astra",
input: [
{
role: "user",
content: "What is the weather like in Paris today?"
}
],
tools: tools
)
puts(response.output.fetch(0).to_json) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 curl -X POST https://api.openai.com/v1/responses \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-astra",
"input": [
{"role": "user", "content": "What is the weather like in Paris today?"}
],
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
}
},
"required": ["location"],
"additionalProperties": false
},
"strict": true
}
]
}' MCP à distance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"tools": [
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "never"
}
],
"input": "Roll 2d4+1"
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "dmcp",
server_description:
"A Dungeons and Dragons MCP server to assist with dice rolling.",
server_url: "https://dmcp-server.deno.dev/mcp",
require_approval: "never",
},
],
input: "Roll 2d4+1",
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-6-astra",
tools=[
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "never",
},
],
input="Roll 2d4+1",
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfMcp("dmcp")
tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")
tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.Tool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("Roll 2d4+1")
.addTool(
Tool.Mcp.builder()
.serverLabel("dmcp")
.serverDescription(
"A Dungeons and Dragons MCP server to assist with dice rolling.")
.serverUrl("https://dmcp-server.deno.dev/mcp")
.requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "dmcp",
serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
)
);
options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 require "openai"
openai = OpenAI::Client.new
response = openai.responses.create(
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "dmcp",
server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",
server_url: "https://dmcp-server.deno.dev/mcp",
require_approval: "never"
}
],
input: "Roll 2d4+1"
)
puts(response.output_text)
Voici un aperçu des outils disponibles sur la plateforme OpenAI. Sélectionnez-en un pour en savoir plus sur son utilisation.
Appelez du code personnalisé pour donner au modèle accès à des données et à des capacités supplémentaires.
Intégrez des données issues d’Internet à la génération des réponses du modèle.
Donnez au modèle accès à de nouvelles capacités via des serveurs Model Context Protocol (MCP).
Importez et réutilisez des ensembles de skills versionnés dans des environnements de shell distant.
Exécutez des commandes shell dans des conteneurs hébergés ou dans votre propre environnement d’exécution local.
Utilisation de l’ordinateur
Créez des workflows agentiques qui permettent à un modèle de contrôler l’interface d’un ordinateur.
Générez ou modifiez des images avec GPT Image.
Recherchez des informations dans le contenu des fichiers importés pour fournir du contexte lors de la génération d’une réponse.
Chargez dynamiquement les outils pertinents dans le contexte du modèle pour optimiser l’utilisation des tokens.
Appel d’outils par programmation
Permettez aux modèles de rédiger et d’exécuter du code JavaScript qui orchestre les appels d’outils.
Lorsque vous envoyez une requête pour générer une réponse du modèle , vous activez généralement l’accès aux outils en les configurant dans le paramètre tools. Chaque outil a ses propres exigences de configuration. Consultez la section Outils disponibles pour obtenir des instructions détaillées.
Le modèle décide automatiquement d’utiliser ou non un outil configuré en fonction du prompt fourni. Par exemple, si votre prompt demande des informations postérieures à la date limite des données d’entraînement du modèle et que la recherche web est activée, le modèle appelle généralement l’outil de recherche web pour récupérer des informations pertinentes et à jour.
Certains workflows avancés peuvent aussi charger des définitions d’outils supplémentaires au cours de l’interaction. Par exemple, la recherche d’outils permet de différer le chargement des définitions de fonctions jusqu’à ce que le modèle les juge nécessaires.
Vous pouvez explicitement contrôler ou orienter ce comportement en définissant le paramètre tool_choice dans la requête API .
L’API Agents exécute la boucle de l’agent pour vous. Configurez les outils dans agent.tools, traitez les appels de fonction dans votre application et connectez un bac à sable lorsque les outils ont besoin d’un environnement d’exécution.
Consultez Fonctions pour appeler le code de votre application, Connexions MCP pour connecter des serveurs d’outils et la configuration du bac à sable pour les outils qui nécessitent un environnement d’exécution. L’appel d’outils par programmation est activé par défaut. La découverte des Skills s’effectue via les répertoires de capacités du bac à sable.
Dans Agents SDK, les outils conservent la même sémantique, mais leur intégration se fait dans la définition de l’agent et la conception du workflow, plutôt que dans une seule requête à l’API Responses.
Rattachez des outils hébergés, des outils de type fonction ou des outils MCP hébergés directement à l’agent lorsqu’un spécialiste doit les appeler lui-même.
Exposez un spécialiste sous forme d’outil lorsqu’un agent gestionnaire doit garder le contrôle de la réponse destinée à l’utilisateur.
Conservez les harnais de shell, d’application de patchs et d’utilisation de l’ordinateur dans votre environnement d’exécution, même lorsque le SDK modélise la décision d’utiliser un outil.
1
2
3
4
5
6
7
8
9
10
11 import { tool } from "@openai/agents" ;
import { z } from "zod" ;
const getWeatherTool = tool ({
name: "get_weather" ,
description: "Get the weather for a given city." ,
parameters: z. object ({ city: z. string () }),
async execute ({ city }) {
return `The weather in ${ city } is sunny.` ;
},
}); 1
2
3
4
5
6
7 from agents import function_tool
@function_tool
def get_weather(city: str) -> str:
"""Get the weather for a given city."""
return f"The weather in {city} is sunny."
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import { Agent } from "@openai/agents" ;
const summarizer = new Agent ({
name: "Summarizer" ,
instructions: "Generate a concise summary of the supplied text." ,
});
const mainAgent = new Agent ({
name: "Research assistant" ,
tools: [
summarizer. asTool ({
toolName: "summarize_text" ,
toolDescription: "Generate a concise summary of the supplied text." ,
}),
],
}); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from agents import Agent
summarizer = Agent(
name="Summarizer",
instructions="Generate a concise summary of the supplied text.",
)
main_agent = Agent(
name="Research assistant",
tools=[
summarizer.as_tool(
tool_name="summarize_text",
tool_description="Generate a concise summary of the supplied text.",
)
],
)
Consultez Définitions d’agents pour concevoir un spécialiste unique, Orchestration et transferts lorsque les outils influent sur la répartition des responsabilités, Garde-fous et révision humaine lorsque les outils ont une incidence sur les approbations, et Intégrations et observabilité lorsque la capacité est fournie par MCP.