credencestack.connectors¶
Connect an agent to the simulated back office. See Connecting your agent for a guided tour.
credencestack.connectors ¶
Connectors connect agents (Python code, HTTP services, LangChain 1.x) to CredenceStack.
Every connector implements :class:~credencestack.connectors.protocol.Connector and drives
the agent inside the simulated environment (see :func:get_connector).
CONNECTORS
module-attribute
¶
CONNECTORS: dict[str, ConnectorSpec] = _spec(
ConnectorSpec(
name="python",
summary="A Python policy or plain callable",
target="module:function",
builder="credencestack.connectors.python:build_connector",
conformance_agent="credencestack.agents:scripted_safe",
),
ConnectorSpec(
name="http",
summary="An agent service implementing the HTTP contract",
target="base URL",
builder="credencestack.connectors.http:build_connector",
),
ConnectorSpec(
name="langchain",
summary="A LangChain 1.x / LangGraph 1.x agent factory",
target="module:factory",
builder="credencestack.connectors.langchain:build_connector",
extra="langchain",
requires=("langchain", "langgraph"),
framework="langchain",
targeted="1.5.2",
conformance_agent="credencestack.agents.safe_lc:build",
),
ConnectorSpec(
name="mcp",
summary="Any MCP-capable agent, launched as a process (Streamable HTTP or stdio)",
target="agent command (--agent-cmd)",
builder="credencestack.connectors.mcp:build_connector",
extra="mcp",
requires=("mcp", "uvicorn"),
framework="mcp",
targeted="2.3.0",
conformance_agent="{python} -m examples.guides.mcp.scripted_agent --mcp-url {mcp_url} --task-file {task_file} --control-port {control_port}",
),
ConnectorSpec(
name="openai-agents",
summary="An OpenAI Agents SDK agent factory",
target="module:factory",
builder="credencestack.connectors.openai_agents:build_connector",
extra="openai-agents",
requires=("agents",),
framework="openai-agents",
targeted="0.25.0",
conformance_agent="examples.guides.openai_agents.agent_safe:build",
),
ConnectorSpec(
name="msaf",
summary="A Microsoft Agent Framework (Python) agent factory",
target="module:factory",
builder="credencestack.connectors.msaf:build_connector",
extra="msaf",
requires=("agent_framework",),
framework="agent-framework-core",
targeted="1.26.0",
conformance_agent="examples.guides.msaf.agent_safe:build",
),
ConnectorSpec(
name="strands",
summary="An AWS Strands Agents agent factory",
target="module:factory",
builder="credencestack.connectors.strands:build_connector",
extra="strands",
requires=("strands",),
framework="strands-agents",
targeted="1.65.0",
conformance_agent="examples.guides.strands.agent_safe:build",
),
ConnectorSpec(
name="adk",
summary="A Google Agent Development Kit (ADK) agent factory",
target="module:factory",
builder="credencestack.connectors.adk:build_connector",
extra="adk",
requires=("google.adk",),
framework="google-adk",
targeted="2.14.1",
conformance_agent="examples.guides.google_adk.agent_safe:build",
),
ConnectorSpec(
name="claude-agent-sdk",
summary="A Claude Agent SDK options factory (in-process MCP tools)",
target="module:factory",
builder="credencestack.connectors.claude_agent_sdk:build_connector",
extra="claude-agent-sdk",
requires=("claude_agent_sdk",),
framework="claude-agent-sdk",
targeted="0.2.188",
conformance_agent="examples.frameworks.claude_agent_sdk.agent_safe:build",
),
ConnectorSpec(
name="crewai",
summary="A CrewAI crew factory (install in its own environment)",
target="module:factory",
builder="credencestack.connectors.crewai:build_connector",
extra="crewai",
requires=("crewai",),
framework="crewai",
targeted="1.15.44",
conformance_agent="examples.guides.crewai.agent_safe:build",
),
)
Connectors by name, in the order connectors list shows them.
CONNECTOR_NAMES
module-attribute
¶
CONNECTOR_NAMES: tuple[str, ...] = tuple(CONNECTORS)
Connector kinds accepted by :func:get_connector (see :mod:.registry).
AgentControl
dataclass
¶
AgentControl(
suspended: bool = False, reason: str | None = None
)
Signals the harness sends to a running agent (read by the agent, set by the harness).
Capabilities ¶
Bases: BaseModel
What a connector (and the agent behind it) supports.
human_in_the_loop
class-attribute
instance-attribute
¶
human_in_the_loop: bool = False
The agent pauses for human approval natively (e.g. LangChain HITL middleware).
step
class-attribute
instance-attribute
¶
step: bool = False
step() advances the agent by one action.
suspend
class-attribute
instance-attribute
¶
suspend: bool = False
The agent system honours a suspension request.
Connector ¶
Bases: Protocol
Drives one agent run at a time. Create a fresh connector (or call start) per epoch.
run_until_done ¶
run_until_done(max_steps: int = 50) -> RunHandle
Run to completion, or until max_steps actions have been taken.
start ¶
start(
task: TaskInfo,
tools: tuple[ToolSpec, ...],
env: Environment,
) -> RunHandle
Begin a run. Tools must be executed through env.call.
suspend ¶
suspend(reason: str) -> bool
Ask the agent to stop. Return False if the agent system cannot be suspended.
ConnectorNotInstalled ¶
ConnectorNotInstalled(
message: str,
*,
hint: str | None = None,
docs: str | None = None,
)
ConnectorOptions
dataclass
¶
ConnectorOptions(
model: str | None = None,
agent_cmd: str | None = None,
control_url: str | None = None,
result_file: str | None = None,
timeout_s: float | None = None,
transport: str | None = None,
)
Options some connectors take, from the command line or Python.
agent_cmd
class-attribute
instance-attribute
¶
agent_cmd: str | None = None
MCP connector: the agent's launch command template.
control_url
class-attribute
instance-attribute
¶
control_url: str | None = None
MCP connector: the agent's control endpoint for suspension.
model
class-attribute
instance-attribute
¶
model: str | None = None
Model string; credencestack:scripted selects the offline scripted model.
result_file
class-attribute
instance-attribute
¶
result_file: str | None = None
MCP connector: a file the agent writes its final answer to (default: stdout).
timeout_s
class-attribute
instance-attribute
¶
timeout_s: float | None = None
External agents: wall-clock time limit per episode.
transport
class-attribute
instance-attribute
¶
transport: str | None = None
MCP connector: http (Streamable HTTP, the default) or stdio.
Policy ¶
Bases: Protocol
A step-wise agent: policy(task, control) returns a generator (see :data:PolicyRun).
PolicyDriver ¶
PolicyDriver(
policy: Policy, task: TaskInfo, control: AgentControl
)
Advances a :class:Policy one action at a time.
next_action(result) sends the previous tool result (None the first time) and
returns either the next :class:ToolCall or the final output dict.
Instantiate policy for task.
next_action ¶
next_action(
result: ToolResult | None,
) -> ToolCall | dict[str, Any]
Return the next tool call, or the final output once the policy returns.
PythonConnector ¶
PythonConnector(agent: str | Callable[..., Any])
Runs a Python policy or plain callable inside the simulated environment.
Wrap agent (a callable or a "module:function" string).
capabilities ¶
capabilities() -> Capabilities
Policies support stepping; both shapes can observe suspension.
run_until_done ¶
run_until_done(max_steps: int = 50) -> RunHandle
Run to completion (policies stop after max_steps actions).
start ¶
start(
task: TaskInfo,
tools: tuple[ToolSpec, ...],
env: Environment,
) -> RunHandle
Begin a run.
step ¶
step() -> RunHandle
Advance a policy by one action.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
for plain callables (use |
RunHandle
dataclass
¶
RunHandle(
done: bool = False,
output: dict[str, Any] | None = None,
error: str | None = None,
steps: int = 0,
suspended: bool = False,
suspend_reason: str | None = None,
)
State of one agent run.
TaskInfo
dataclass
¶
TaskInfo(
text: str, inputs: Mapping[str, Any] = dict[str, Any]()
)
What the agent is asked to do: free text plus structured inputs.
ToolCall
dataclass
¶
ToolCall(
name: str,
args: dict[str, Any] = dict[str, Any](),
id: str = "",
)
A tool call proposed by a policy.
ToolResult
dataclass
¶
ToolResult(
call: ToolCall,
ok: bool,
result: Any = None,
error: str | None = None,
)
The outcome of a tool call, as the agent sees it.
get_connector ¶
get_connector(
kind: str,
target: str,
options: ConnectorOptions | None = None,
) -> Connector
Build a connector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
A connector name from :data: |
required |
target
|
str
|
What to connect to. |
required |
options
|
ConnectorOptions | None
|
Connector options (model, external-agent settings). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
unknown kind or malformed target. |
ConnectorNotInstalled
|
the connector's optional extra is not installed. |
load_callable ¶
load_callable(
target: str, *, add_cwd_to_path: bool = True
) -> Callable[..., Any]
Import "package.module:function" (dotted attributes allowed after the colon).
Loading executes the module's code; only load agents you trust. When
add_cwd_to_path is true the current directory is put on sys.path so local
modules such as my_agents.payments resolve from the CLI.
Raises:
| Type | Description |
|---|---|
ValueError
|
malformed target, or the attribute is not callable. |
ImportError / AttributeError
|
module or attribute not found. |