R6 class representing an enhanced session for multi-agent systems. Extends ChatSession with:
Execution context tracking (call stack, delegation history)
Sandboxed code execution with safety guardrails
Variable scoping and access control
Comprehensive tracing and observability
aisdk::ChatSession -> SharedSession
Inherited methods
aisdk::ChatSession$append_message()aisdk::ChatSession$as_list()aisdk::ChatSession$checkpoint()aisdk::ChatSession$clear_history()aisdk::ChatSession$clear_memory()aisdk::ChatSession$eval_in_session()aisdk::ChatSession$get_envir()aisdk::ChatSession$get_history()aisdk::ChatSession$get_last_response()aisdk::ChatSession$get_memory()aisdk::ChatSession$get_metadata()aisdk::ChatSession$get_model_id()aisdk::ChatSession$list_envir()aisdk::ChatSession$list_memory()aisdk::ChatSession$list_metadata()aisdk::ChatSession$merge_metadata()aisdk::ChatSession$restore()aisdk::ChatSession$restore_checkpoint()aisdk::ChatSession$restore_from_list()aisdk::ChatSession$save()aisdk::ChatSession$send()aisdk::ChatSession$send_stream()aisdk::ChatSession$set_memory()aisdk::ChatSession$set_metadata()aisdk::ChatSession$stats()aisdk::ChatSession$switch_model()
new()Initialize a new SharedSession.
SharedSession$new(
model = NULL,
system_prompt = NULL,
tools = NULL,
hooks = NULL,
max_steps = 10,
registry = NULL,
sandbox_mode = "strict",
trace_enabled = TRUE
)modelA LanguageModelV1 object or model string ID.
system_promptOptional system prompt for the conversation.
toolsOptional list of Tool objects.
hooksOptional HookHandler object.
max_stepsMaximum steps for tool execution loops. Default 10.
registryOptional ProviderRegistry for model resolution.
sandbox_modeSandbox mode: "strict", "permissive", or "none". Default "strict".
trace_enabledEnable execution tracing. Default TRUE.
push_context()Push an agent onto the execution stack.
SharedSession$push_context(agent_name, task, parent_agent = NULL)agent_nameName of the agent being activated.
taskThe task being delegated.
parent_agentName of the delegating agent (or NULL for root).
Invisible self for chaining.
pop_context()Pop the current agent from the execution stack.
SharedSession$pop_context(result = NULL)resultOptional result from the completed agent.
The popped context, or NULL if stack was empty.
get_context()Get the current execution context.
SharedSession$get_context()A list with current_agent, depth, and delegation_stack.
set_global_task()Set the global task (user's original request).
SharedSession$set_global_task(task)taskThe global task description.
Invisible self for chaining.
execute_code()Execute R code in a sandboxed environment.
SharedSession$execute_code(
code,
scope = "global",
timeout_ms = 30000,
capture_output = TRUE
)codeR code to execute (character string).
scopeVariable scope: "global", "agent", or a custom scope name.
timeout_msExecution timeout in milliseconds. Default 30000.
capture_outputCapture stdout/stderr. Default TRUE.
A list with result, output, error, and duration_ms.
get_var()Get a variable from a specific scope.
SharedSession$get_var(name, scope = "global", default = NULL)nameVariable name.
scopeScope name. Default "global".
defaultDefault value if not found.
The variable value or default.
set_var()Set a variable in a specific scope.
SharedSession$set_var(name, value, scope = "global")nameVariable name.
valueVariable value.
scopeScope name. Default "global".
Invisible self for chaining.
list_vars()List variables in a scope.
SharedSession$list_vars(scope = "global", pattern = NULL)scopeScope name. Default "global".
patternOptional pattern to filter names.
Character vector of variable names.
summarize_vars()Get a summary of all variables in a scope.
SharedSession$summarize_vars(scope = "global")scopeScope name. Default "global".
A data frame with name, type, and size information.
create_scope()Create a new variable scope.
SharedSession$create_scope(scope_name, parent_scope = "global")scope_nameName for the new scope.
parent_scopeParent scope name. Default "global".
Invisible self for chaining.
delete_scope()Delete a variable scope.
SharedSession$delete_scope(scope_name)scope_nameName of the scope to delete.
Invisible self for chaining.
trace_event()Record a trace event.
SharedSession$trace_event(event_type, data = list())event_typeType of event (e.g., "context_push", "code_execution").
dataEvent data as a list.
Invisible self for chaining.
get_trace()Get the execution trace.
SharedSession$get_trace(event_types = NULL, agent = NULL)event_typesOptional filter by event types.
agentOptional filter by agent name.
A list of trace events.
clear_trace()Clear the execution trace.
SharedSession$clear_trace()Invisible self for chaining.
trace_summary()Get trace summary statistics.
SharedSession$trace_summary()A list with event counts, agent activity, and timing info.
set_access_control()Set access control for an agent.
SharedSession$set_access_control(agent_name, permissions)agent_nameAgent name.
permissionsList of permissions (read_scopes, write_scopes, tools).
Invisible self for chaining.
check_permission()Check if an agent has permission for an action.
SharedSession$check_permission(agent_name, action, target)agent_nameAgent name.
actionAction type: "read", "write", or "tool".
targetTarget scope or tool name.
TRUE if permitted, FALSE otherwise.
get_sandbox_mode()Get sandbox mode.
SharedSession$get_sandbox_mode()The current sandbox mode.
set_sandbox_mode()Set sandbox mode.
SharedSession$set_sandbox_mode(mode)modeSandbox mode: "strict", "permissive", or "none".
Invisible self for chaining.
clone()The objects of this class are cloneable with this method.
SharedSession$clone(deep = FALSE)deepWhether to make a deep clone.