Documentation Index Fetch the complete documentation index at: https://afk.arpan.sh/llms.txt
Use this file to discover all available pages before exploring further.
This page is a single-source reference for every configuration knob in AFK. Each section lists fields with their type, default value, and purpose.
Agent
The Agent constructor defines what your agent is — identity, model, tools, and behavior.
from afk.agents import Agent
Field Type Default Description modelstr | LLMrequired LLM model name or pre-built client instance namestrclass name Agent identity for logs, telemetry, and subagent routing instructionsstr | callableNoneSystem prompt — static string or callable provider instruction_filestr | PathNonePath to a prompt file that must resolve under prompts_dir prompts_dirstr | PathNoneRoot directory for prompt files (env: AFK_AGENT_PROMPTS_DIR) toolslist[]Typed functions the agent can call subagentslist[Agent][]Specialist agents this agent can delegate to context_defaultsdict{}Default JSON context merged into each run inherit_context_keyslist[str][]Context keys accepted from a parent subagent model_resolvercallableNoneCustom function to resolve model names to LLM clients skillslist[str][]Skill names to resolve under skills_dir mcp_serverslist[]External MCP server refs whose tools to expose skills_dirstr | Path.agents/skillsRoot directory for skill definitions instruction_roleslist[]Callbacks that append dynamic instruction text policy_roleslist[]Callbacks that can allow/deny/defer runtime actions policy_enginePolicyEngineNoneDeterministic rule engine applied before policy roles subagent_routerSubagentRouterNoneRouter callback deciding subagent targets max_stepsint20Maximum reasoning/tool loop steps tool_parallelismintNoneMax concurrent tool calls (falls back to fail_safe) subagent_parallelism_modestrconfigurablesingle, parallel, or configurablefail_safeFailSafeConfigdefaults Runtime limits and failure policies reasoning_enabledbool | NoneNoneDefault request thinking flag for this agent reasoning_effortstr | NoneNoneDefault request thinking_effort label reasoning_max_tokensint | NoneNoneDefault request max_thinking_tokens enable_skill_toolsboolTrueAuto-register built-in skill tools enable_mcp_toolsboolTrueAuto-register tools from configured MCP servers runnerRunnerNoneOptional runner override
Reasoning override precedence
Reasoning values are resolved in this order:
Run context override: context[\"_afk\"][\"reasoning\"]
Agent defaults: reasoning_enabled, reasoning_effort, reasoning_max_tokens
Provider defaults/validation in the LLM layer
RunnerConfig
Passed to Runner(config=RunnerConfig(...)) to control runtime behavior.
from afk.core import RunnerConfig
Field Type Default Description interaction_modestrheadlessheadless, interactive, or externalapproval_timeout_sfloat300.0Timeout for deferred approval decisions input_timeout_sfloat300.0Timeout for deferred user-input decisions approval_fallbackstrdenyFallback when approval times out: allow, deny, defer input_fallbackstrdenyFallback when user input times out sanitize_tool_outputboolTrueSanitize model-visible tool output untrusted_tool_preambleboolTrueInject untrusted-data warning preamble tool_output_max_charsint12_000Max tool output characters forwarded to model default_sandbox_profileSandboxProfileNoneDefault sandbox profile for tool execution sandbox_profile_providercallableNoneRuntime sandbox profile resolver secret_scope_providercallableNoneSecret-scope resolver per tool call default_allowlisted_commandstuple[str]ls, cat, head, tail, rg, find, pwd, echoAllowlisted shell commands for runtime tools max_parallel_subagents_globalint64Global cap for concurrent subagent tasks max_parallel_subagents_per_parentint8Per-parent-run cap for concurrent subagent fanout max_parallel_subagents_per_target_agentint4Per-target-agent cap subagent_queue_backpressure_limitint512Max pending subagent nodes before backpressure checkpoint_async_writesboolTrueEnable background checkpoint/state writes checkpoint_queue_maxsizeint1024Max queued checkpoint write jobs checkpoint_flush_timeout_sfloat10.0Timeout for terminal checkpoint flush checkpoint_coalesce_runtime_stateboolTrueCoalesce repeated runtime_state checkpoint writes debugboolFalseEnable debug metadata in emitted run events debug_configRunnerDebugConfig | NoneNoneAdvanced debug controls (verbosity/content/redaction) background_tools_enabledboolTrueEnable deferred/background tool orchestration background_tool_default_grace_sfloat0.0Wait this long after defer to allow fast background completion before continuing background_tool_max_pendingint256Maximum unresolved background tool tickets per run background_tool_poll_interval_sfloat0.5Poll interval for external/persisted ticket resolution background_tool_result_ttl_sfloat3600.0TTL before pending ticket is marked failed (runtime floor is 1.0s) background_tool_interrupt_on_resolveboolTrueWhen enabled, resolved tickets can be ingested immediately after defer/grace in the same step
Deep Dive: Interaction Models
The interaction_mode setting fundamentally changes how the Runner handles decision points like tool approval or user input requests.
headless (default) : The Runner never pauses.
If a policy returns defer or request_user_input, the Runner immediately uses the configured approval_fallback or input_fallback (default: deny).
Use case: Backend workers, cron jobs, automated testing.
interactive : The Runner pauses execution and uses the configured InteractionProvider to ask for human input.
For CLI apps, this prints to stdout and reads from stdin.
The run blocks until input is received or approval_timeout_s expires.
Use case: Local CLI tools, scripts run by humans.
external : The Runner emits a run_paused event and suspends execution .
The run() loop exits (or yields a paused state). The state is persisted to memory.
The system waits for an external API call to runner.resume_with_input().
Use case: Chatbots, web UIs, Slack bots where the user is asynchronous.
FailSafeConfig
Passed to Agent(fail_safe=FailSafeConfig(...)) to set runtime limits and failure policies.
from afk.agents import FailSafeConfig
Field Type Default Description llm_failure_policyFailurePolicyretry_then_failStrategy when LLM calls fail tool_failure_policyFailurePolicycontinue_with_errorStrategy when tool calls fail subagent_failure_policyFailurePolicycontinueStrategy when subagent calls fail approval_denial_policyFailurePolicyskip_actionStrategy when approval is denied or times out max_stepsint20Maximum run loop iterations max_wall_time_sfloat300.0Maximum wall-clock runtime in seconds max_llm_callsint50Maximum number of LLM invocations max_tool_callsint200Maximum number of tool invocations max_parallel_toolsint16Max concurrent tools per batch max_subagent_depthint3Maximum subagent recursion depth max_subagent_fanout_per_stepint4Maximum subagents selected per step max_total_cost_usdfloat | NoneNoneCost ceiling for run termination fallback_model_chainlist[str][]Ordered fallback model list for LLM retries breaker_failure_thresholdint5Circuit breaker open threshold breaker_cooldown_sfloat30.0Circuit breaker cooldown window in seconds
Deep Dive: Failure & Recovery
FailSafeConfig controls the agent’s resilience. The policies work in a hierarchy:
Lower-level retries : Transient errors (network glitches, rate limits) are retried automatically by the LLM client, guided by AFK_LLM_MAX_RETRIES.
llm_failure_policy : If the LLM call fails after all retries (or hits a terminal error like 401 Unauthorized):
retry_then_fail: Tries a few more times at the agent level, then fails the run.
retry_then_degrade: Tries again, then marks the run as degraded but returns partial results (useful for “best effort” responses).
tool_failure_policy : If a tool raises an exception:
continue_with_error (default): The error message is fed back to the model. The model can then try to fix its mistake or apologize. This is usually the best setting for capable models.
fail_run: Immediately stops the run. Use this for critical transactional agents where any error is unacceptable.
Circuit Breakers :
If a model provider fails breaker_failure_threshold times in a row, the circuit opens.
Subsequent calls fail instantly without network traffic until breaker_cooldown_s passes.
This protects your system (and wallet) from hammering a down service.
FailurePolicy values
Value Behavior retry_then_failRetry with backoff, then fail the run retry_then_degradeRetry with backoff, then degrade (partial result) retry_then_continueRetry with backoff, then continue without the result fail_fastFail immediately, no retries fail_runFail the entire run continue_with_errorContinue, passing the error to the model continueContinue silently, ignoring the failure skip_actionSkip the action entirely
SandboxProfile
Controls execution restrictions for tool handlers. Configured via RunnerConfig.default_sandbox_profile.
from afk.tools import SandboxProfile
Field Type Default Description profile_idstrdefaultProfile identifier for logs and policy allow_networkboolFalseWhether tools can make network requests allow_command_executionboolFalseWhether tools can execute shell commands allowed_command_prefixeslist[str][]Allowed command prefixes (empty = none) deny_shell_operatorsboolTrueBlock pipes, redirects, semicolons allowed_pathslist[str][]Restrict file access to these paths denied_pathslist[str][]Explicitly deny access to these paths command_timeout_sfloat | NoneNoneKill commands after this duration max_output_charsint20_000Truncate command output beyond this limit
Runner constructor
The Runner accepts these arguments directly (outside of RunnerConfig):
from afk.core import Runner
runner = Runner(
memory_store = ... , # MemoryStore instance
interaction_provider = ... , # InteractionProvider for HITL
policy_engine = ... , # PolicyEngine instance
telemetry = ... , # "console" | "otel" | "json" | TelemetrySink
telemetry_config = ... , # Backend-specific config dict
config = ... , # RunnerConfig instance
)
Argument Type Default Description memory_storeMemoryStoreNoneMemory backend (resolved from env if None) interaction_providerInteractionProviderNoneHuman-in-the-loop provider (required for non-headless) policy_enginePolicyEngineNoneDeterministic policy engine shared across runs telemetrystr | TelemetrySinkNoneTelemetry sink instance or backend id telemetry_configdictNoneBackend-specific sink configuration configRunnerConfigRunnerConfig()Runner configuration
from afk.tools import tool
Argument Type Default Description args_modelType[BaseModel]required Pydantic model for argument validation namestrfunction name Tool name exposed to the LLM descriptionstrdocstring Tool description for the LLM timeoutfloatNoneExecution timeout in seconds prehookslist[PreHook]NoneArgument transform hooks posthookslist[PostHook]NoneOutput transform hooks middlewareslist[Middleware]NoneExecution wrappers (logging, caching, etc.) raise_on_errorboolFalseRaise exceptions instead of returning ToolResult(success=False)
Next steps
Environment Variables Environment variable defaults and backend selection.
API Reference Quick import reference.