Teleon Library Patterns
Practical patterns for TeleonClient, agents, tools, LLM gateway, integrations, testing, and remote agents
The Teleon Python library is the main integration surface for defining agents and tools.
For the complete Python API surface (all methods, options, and defaults), see the Teleon Library page in API Reference.
Teleon Library
SDK & client APIs
from teleon import TeleonClient
client = TeleonClient(
api_key="tlk_live_xxx",
environment="production",
base_url=None,
verify_key=True,
is_paid_tier=False,
)
API key formats:
tlk_live_xxx (production)
tlk_test_xxx (test)
teleon_xxx (legacy)
Agent functions must be async and return a value.
@client.agent(name="support", model="gpt-4")
async def support_agent(query: str) -> str:
return "ok"
from teleon import tool
@tool(name="calculator", category="math")
async def calculate(expression: str) -> float:
return eval(expression)
from teleon.tools import get_registry
registry = get_registry()
await registry.register(tool)
tool = registry.get("calculator")
tools = registry.list_tools(category=ToolCategory.MATH)
results = registry.search("calculate")
stats = registry.get_stats()
The LLM Gateway provides a unified interface for multiple LLM providers.
from teleon.llm.gateway import configure_gateway
from teleon.llm import LLMMessage, LLMConfig
gateway = configure_gateway(
openai_api_key="sk-xxx",
anthropic_api_key="sk-ant-xxx",
enable_cache=True,
cache_ttl=3600,
)
messages = [LLMMessage(role="user", content="Hello!")]
config = LLMConfig(model="gpt-4", temperature=0.7, max_tokens=500, use_cache=True)
response = await gateway.complete(messages, config)
Streaming:
async for chunk in gateway.stream_complete(messages, config):
print(chunk, end="")
Example: Slack integration.
from teleon.integrations.slack import SlackIntegration
from teleon.integrations.base import IntegrationConfig
config = IntegrationConfig(name="slack", api_key="xoxb-your-bot-token")
slack = SlackIntegration(config)
await slack.authenticate()
await slack.send_message("#general", "Hello from Teleon!")
await slack.close()
from teleon.testing import AgentTestCase, ToolTestCase, IntegrationTestCase
Interact with deployed agents from your applications.
from teleon import TeleonClient
client = TeleonClient(api_key="tlk_live_xxx")
agent = await client.get_remote_agent("customer-support")
agents = await client.list_deployed_agents()
Execute and batch execute:
result = await agent.execute(
input_data={"query": "Help me with billing"},
temperature=0.7,
max_tokens=500,
metadata={"session_id": "123"},
)
results = await agent.execute_batch(
inputs=[
{"query": "Question 1"},
{"query": "Question 2"},
{"query": "Question 3"},
],
parallel=True,
)
Remote Cortex access:
results = await agent.cortex.search(query="billing issues", limit=10)
await agent.cortex.store(content="Important information", metadata={"type": "note"})
stats = await agent.cortex.get_stats()
Teleon provides a comprehensive exception hierarchy.
from teleon.core import (
TeleonError,
ConfigurationError,
AgentExecutionError,
AgentValidationError,
LLMRateLimitError,
)
try:
result = await my_agent("query")
except LLMRateLimitError as e:
await asyncio.sleep(e.retry_after)
result = await my_agent("query")
except AgentExecutionError as e:
logging.error(f"Agent failed: {e}")
except TeleonError as e:
logging.error(f"Teleon error: {e}")