Skip to main content

Observability

Observability helps answer three questions: what did the agent do, how long did each step take, and how much did model usage cost? ISH can record a timeline of model and tool activity, collect usage and timing totals, send run details to a monitoring service, and enforce configured limits. You can enable only the pieces your application needs. A trace is the connected timeline for one run; each timed item in that timeline is called a span by common monitoring tools.

from ish import Agent, BaseInterceptor, LifecycleContext, MetricsInterceptor


class PerformanceLogger(BaseInterceptor):
async def after_tool(self, ctx: LifecycleContext) -> None:
if ctx.duration_ms is not None:
print(f"Tool '{ctx.entity_name}' executed in {ctx.duration_ms:.2f} ms")


metrics = MetricsInterceptor()
agent = Agent(
name="profiled_assistant",
model="gpt-4o-mini",
interceptors=[metrics, PerformanceLogger()],
)

# After running the agent:
print(metrics.metrics)

Trace privacy, run budgets​

Control repeated calls​

Use repeated-call detection to stop a run that keeps making the same tool call. Use cost limits when the model or provider supplies enough pricing information to estimate spend; ISH rejects incomplete or invalid cost data rather than treating it as zero.

ControlPurpose
Repeated-call detectionStops identical tool calls from looping
max_cost_usdCaps estimated model cost for a run
max_total_tokensCaps token use across model calls

Measure latency​

All six SDKs provide a shared metrics collector alongside custom per-event timing hooks. It records model and tool calls, errors, usage, and elapsed time:


Set model call limits​

To prevent infinite loops when an agent struggles with a tricky task, configure the built-in max_turns / MaxTurns limit on the agent runner or enforce a dynamic quota inside before_llm / before_model:

from ish import Agent, BaseInterceptor, LifecycleContext


class ModelCallBudgetGuardrail(BaseInterceptor):
def __init__(self, max_calls: int = 5):
self.max_calls = max_calls
self.calls = 0

async def before_llm(self, ctx: LifecycleContext) -> None:
self.calls += 1
if self.calls > self.max_calls:
raise RuntimeError(
f"Execution aborted: exceeded model call budget of {self.max_calls}."
)


agent = Agent(
name="bounded_assistant",
model="gpt-4o-mini",
max_turns=5,
interceptors=[ModelCallBudgetGuardrail(max_calls=5)],
)

Send run details to monitoring tools​

ish can send run timelines to Langfuse and other services that accept the OpenTelemetry format, a common format for monitoring data. The monitoring service stores and displays the run details it receives. You can inspect the order and timing of model and tool activity without changing the agent's model or tools.

trace_export_data settingWhat gets sentWhen to use it
"none"Omits prompt, tool input, and result values from exported detailsWhen those values may contain sensitive information
"digest" (default)Sends short previews; long text and large lists are shortenedFor routine troubleshooting with limited detail
"full"Sends complete prompt, tool input, and result valuesOnly when full content is needed and the destination is trusted

Example Langfuse trace view from Langfuse's documentation. This is a generic Langfuse example, not a screenshot of an ISH run.

Example trace detail from the Langfuse tracing guide. The screenshot illustrates Langfuse's interface; data shown is not produced by ISH.

Key Capabilities​

  1. Run order and timing: exported records show the order and duration of model and tool activity.
  2. Input and output detail: the trace_export_data setting controls how much prompt, tool input, and result content is sent.
  3. Context activity: context tool calls can appear in the timeline when they emit activity events. The default digest mode may omit some stored values.

The default trace_export_data="digest" shortens long values but can still send complete short values. It does not guarantee that sensitive information is hidden. Choose "none" when exported prompt, tool input, and result content must be excluded. Choose "full" only when the destination is trusted and you need complete values for debugging.

Configuration Example​

Set your Langfuse project credentials and host in the environment:

export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_HOST="https://cloud.langfuse.com"
import asyncio

from ish import Agent, OTelGenAIInterceptor


async def main() -> None:
interceptor = OTelGenAIInterceptor(
preset="langfuse",
service_name="finance-workflow",
trace_export_data="digest",
)
agent = Agent(
name="financial_analyst",
model="gpt-4o",
interceptors=[interceptor],
)
result = await agent.run("Analyze Q4 performance and save key metrics.")
print(result.content)


asyncio.run(main())

Exporter Presets (otel.resolve_exporter)​

PresetDefault EndpointAuthentication Header
"langfuse"{LANGFUSE_HOST}/api/public/otel/v1/traces (defaults LANGFUSE_HOST to http://localhost:3000)HTTP Basic auth (LANGFUSE_PUBLIC_KEY / LANGFUSE_SECRET_KEY)
"langtrace"https://api.langtrace.ai/api/tracex-api-key
"phoenix"http://localhost:6006/v1/tracesNone by default
Default monitoring collectorhttp://localhost:4318/v1/tracesCustom headers if configured

Set LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST in the environment before running the Langfuse example above. See Langfuse's OpenTelemetry setup guide for region endpoints and project-key details.