Metadata-Version: 2.4
Name: agentlens-kk
Version: 0.1.2
Summary: AgentLens Python SDK — fleet governance for multi-framework agent stacks
License: MIT
Project-URL: Homepage, https://agentlens-api-production.up.railway.app
Project-URL: Repository, https://github.com/kk-studio/agentlens
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.0
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.2; extra == "langchain"
Requires-Dist: langchain>=0.2; extra == "langchain"
Provides-Extra: crewai
Requires-Dist: crewai>=0.70; extra == "crewai"
Provides-Extra: autogen
Requires-Dist: autogen-agentchat>=0.4; extra == "autogen"
Provides-Extra: llamaindex
Requires-Dist: llama-index-core>=0.10; extra == "llamaindex"
Provides-Extra: all
Requires-Dist: langchain-core>=0.2; extra == "all"
Requires-Dist: langchain>=0.2; extra == "all"
Requires-Dist: crewai>=0.70; extra == "all"
Requires-Dist: autogen-agentchat>=0.4; extra == "all"
Requires-Dist: llama-index-core>=0.10; extra == "all"

# AgentLens Python SDK

Fleet governance for multi-framework agent stacks.

```bash
pip install agentlens-sdk                     # core
pip install "agentlens-sdk[langchain]"        # + LangChain
pip install "agentlens-sdk[crewai]"           # + CrewAI
pip install "agentlens-sdk[autogen]"          # + AutoGen
pip install "agentlens-sdk[all]"              # everything
```

API: `https://agentlens-api-production.up.railway.app`

---

## Quick start (any framework)

```python
import agentlens

agentlens.init("al_live_xxx")  # or set AGENTLENS_API_KEY env var

with agentlens.trace("my-agent") as run:
    result = my_agent.run(input)
    run.tool_call("search", input="query", output="results")
    run.complete(result)
```

## Decorator style

```python
import agentlens

agentlens.init("al_live_xxx")

@agentlens.monitor
def my_agent(input):
    return result

# or with options:
@agentlens.monitor(agent_id="my-agent")
async def my_async_agent(input):
    return result
```

## Record tools without a trace context

```python
agentlens.record_tool("send_email", input="to: user@example.com", output="sent")
```

---

## LangChain (auto-instrumented)

```python
import agentlens

agentlens.init("al_live_xxx")
# LangChain detected and instrumented automatically
agent.invoke({"input": "..."})
```

Or manually:

```python
from agentlens import AgentTracer
from agentlens.langchain import AgentLensCallbackHandler

tracer = AgentTracer(api_key="...", api_url="https://agentlens-api-production.up.railway.app", agent_id="my-agent")
handler = AgentLensCallbackHandler(tracer)
result = executor.invoke({"input": "..."}, config={"callbacks": [handler]})
tracer.shutdown()
```

## CrewAI

```python
from agentlens.crewai import AgentLensCrewListener

listener = AgentLensCrewListener(api_key="...", api_url="https://agentlens-api-production.up.railway.app", agent_id="my-crew")
crew = Crew(agents=[...], tasks=[...], event_listeners=[listener])
crew.kickoff()
```

## AutoGen

```python
import agentlens

agentlens.init("al_live_xxx")
agentlens.wrap_agent(assistant)   # registers hooks on the agent instance
chat_result = assistant.initiate_chat(user_proxy, message="...")
```

Or manually:

```python
from agentlens.autogen import AgentLensAutoGenHook, wrap_agent

hook = AgentLensAutoGenHook(api_key="...", api_url="https://agentlens-api-production.up.railway.app", agent_id="my-agent")
wrap_agent(assistant, hook)
chat_result = assistant.initiate_chat(user_proxy, message="...")
hook.tracer.shutdown()
```

---

## Event types

All event types match `packages/core/src/schema.ts`:

| Category | Types |
|---|---|
| Agent | `agent.started` `agent.completed` `agent.failed` `agent.paused` |
| Step | `step.started` `step.completed` `step.failed` `step.retried` |
| Tool | `tool.called` `tool.returned` `tool.errored` |
| LLM | `llm.request` `llm.response` `llm.hallucination_suspected` |
| Memory | `memory.read` `memory.write` |
| HITL | `hitl.checkpoint_created` `hitl.approved` `hitl.rejected` `hitl.timeout` |
| Cost | `cost.token_usage` |
