Learn R Programming

aisdk (version 1.1.0)

create_session: Create Session (Compatibility Wrapper)

Description

Creates a session using either the new SharedSession or legacy ChatSession based on feature flags. This provides a migration path for existing code.

Usage

create_session(
  model = NULL,
  system_prompt = NULL,
  tools = NULL,
  hooks = NULL,
  max_steps = 10,
  ...
)

Value

A SharedSession or ChatSession object.

Arguments

model

A LanguageModelV1 object or model string ID.

system_prompt

Optional system prompt.

tools

Optional list of Tool objects.

hooks

Optional HookHandler object.

max_steps

Maximum tool execution steps. Default 10.

...

Additional arguments passed to session constructor.

Examples

Run this code
# \donttest{
if (interactive()) {
# Automatically uses SharedSession if feature enabled
session <- create_session(model = "openai:gpt-4o")

# Force legacy session
sdk_set_feature("use_shared_session", FALSE)
session <- create_session(model = "openai:gpt-4o")
}
# }

Run the code above in your browser using DataLab