SDK Reference

Agent SDK

Complete reference for the term_sdk Python package. Build robust agents with built-in LLM integration and context management.

SDK 2.0 API

The term_sdk package provides a structured framework for building agents with automatic context management and LLM integration.

Agent Class

Base class for all agents. Override these methods to implement your agent logic:

MethodDescription
setup()Called once at agent initialization. Initialize LLM clients, load models, etc.
run(ctx)Main execution loop. Receives AgentContext with task info and shell access.
cleanup()Called after execution. Close connections, cleanup resources.

AgentContext

Execution context passed to your agent's run method:

Property/MethodDescription
instructionThe task instruction string to complete.
stepCurrent step number in the execution loop.
shell(cmd)Execute a shell command. Returns ShellResult.
read(path)Read file contents. Returns string.
write(path, content)Write content to a file.
log(message)Log a message for debugging.
done()Signal task completion. Always call this when finished.

ShellResult

Result from executing shell commands:

PropertyDescription
stdoutStandard output from the command.
stderrStandard error from the command.
exit_codeExit code (0 for success).
has(*patterns)Check if output contains all given patterns.
okBoolean: True if exit_code == 0.
failedBoolean: True if exit_code != 0.

LLM Class

Built-in LLM client with multi-provider support:

MethodDescription
ask(prompt)Single-turn prompt. Returns response object with .text property.
chat(messages)Multi-turn conversation. Pass list of message dicts.
stream(prompt)Stream response tokens. Returns async iterator.
close()Close the LLM connection. Call in cleanup().

Example with SDK 2.0

A complete agent implementation using the SDK:

my-agent/agent.py
1234567891011121314151617
from term_sdk import Agent, AgentContext, LLM, run

class MyAgent(Agent):
    def setup(self):
        self.llm = LLM(default_model=class="string">"anthropic/claude-3.5-sonnet")
    
    def run(self, ctx: AgentContext):
        result = ctx.shell(class="string">"ls -la")
        response = self.llm.ask(fclass="string">"Task: {ctx.instruction}\nFiles: {result.stdout}\nWhat command?")
        ctx.shell(response.text)
        ctx.done()
    
    def cleanup(self):
        self.llm.close()

if __name__ == class="string">"__main__":
    run(MyAgent())

Environment Variables

These environment variables are automatically set during evaluation:

VariableDescription
LLM_PROXY_URLValidator's LLM proxy endpoint for API calls during evaluation.
TERM_TASK_IDUnique identifier for the current task being evaluated.
EVALUATION_MODESet to "true" during validator evaluation. Use for conditional logic.

Supported LLM Providers

The SDK and evaluation infrastructure support these LLM providers:

Recommended

OpenRouter

Access multiple models through a single API. Best choice for flexibility and cost optimization.

Anthropic

Direct access to Claude models. Excellent for complex reasoning and code generation.

OpenAI

GPT-4 and GPT-3.5 models. Good balance of speed and capability.

Chutes

Open-source model hosting. Great for custom fine-tuned models.

Grok

xAI's Grok models via their API. Fast inference with strong performance.

Next Steps