Commit Graph

37 Commits

Author SHA1 Message Date
Aurélien Sibiril
3cebf7a1df Refine tool dispatch errors in resume path
Prefix the unknown-tool error with the "cannot" convention and drop
the duplicate wrap around executeSingleTool: that helper already wraps
its generic error path, so the outer wrap produced messages shaped like
"cannot execute tool X: cannot execute tool X: ...".

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
d13c83c19f Snapshot MaxTurns in checkpoint and apply it on restore
MaxTurns is the only agent bound compared against a counter that is
serialised in the checkpoint (Turns). When config drifts between save
and restore -- typically because a deploy changed WithMaxTurns or a
different build of the agent is registered by name -- cp.Turns can
exceed agent.maxTurns on the resumed run, which previously surfaced
as a warning log and then a MaxTurnsExceededError on the first
iteration of the resumed coreLoop.

Capture MaxTurns in the new AgentConfig on every save, and on
restore clone the registry-resolved agent with WithMaxTurns applied
from the snapshot. The override flows through the outer Restore path
and through both inner-agent resolution sites in
restoreNestedSuspended and restoreAwaitingApproval, so nested
runs get the same treatment. Other loop bounds
(maxEmptyOutputRetries, maxToolDepth) reset per turn / per tool
depth and stay intentionally live so deploys can tune them without
invalidating in-flight checkpoints. Live references (tools, hooks,
LLM client, approval callbacks, guardrails) are not snapshotted for
the same reason.

With the snapshot in place, the "restored agent run has already
reached max turns" warning at the top of continueFromMessages is
structurally unreachable -- the live agent's bound is now the same
value cp.Turns was bounded by at save time -- and is removed.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
fb88318c54 Fix suspension checkpoint fallback in nested and parallel execution
executeParallel ignored SuspendedError when checkpoint was nil,
treating it as a normal tool error. Nested suspension propagation
also dropped the in-memory checkpoint when persistence failed,
making runs non-resumable.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
71e2d00b3a Rename CheckpointStatus to AgentStatus
The status values describe the agent state, not the
checkpoint data state.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
ff18a5fc23 Remove json tags from internal structs
JSON marshaling uses field names directly; explicit tags
are unnecessary at this level.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
e831ee3c63 Add agent run supervisor worker
Poll-based supervisor that claims PENDING agent runs with FOR UPDATE
SKIP LOCKED, runs them with lease-based heartbeat, and handles
graceful shutdown. On infrastructure stop the row stays RUNNING so
stale recovery resets it to PENDING on restart; Restore picks up
from the last checkpoint. Heartbeat loss cancels execution without
committing a terminal status.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
363d696906 Add Restore function for agent checkpoint recovery
Restore loads a checkpoint from the store, resolves the agent from
a registry, and re-enters coreLoop. Handles suspended, nested
suspended (concurrent inner restore), and awaiting-approval states.
Partial progress is saved when some inner agents complete while
others remain suspended.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
7d5b933aa4 Add checkpoint persistence to agent core loop
coreLoop now saves incremental checkpoints after each tool-call turn
and checks a cooperative stop signal at turn boundaries. SuspendedError
is handled in finishRun, executeParallel, and executeSingleTool.
Approval-interrupted checkpoints are persisted for both flat and
nested interruptions.

Introduce RunOption, WithCheckpointStore, RunWithOpts, ResumeWithOpts,
and RunStreamedWithOpts so callers can provide checkpoint storage.
Add StreamEventSuspended and OnRunRestore hook.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Aurélien Sibiril
51df618c93 Add checkpoint types and stop signal for agent suspension
Introduce Checkpoint, CheckpointStore, SuspendedError, AgentRegistry,
and CompletedCall types. Add cooperative stop signal via context.
Export CompletedCall (was unexported completedCall) so checkpoints
can reference completed tool results. Add JSON tags to ToolResult
and ApprovalResult for checkpoint serialization.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-26 22:58:21 +02:00
Sacha Al Himdani
ab5654f6e5 Fix errcheck and ineffassign lint errors
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
2026-04-24 14:24:48 +02:00
Aurélien Sibiril
509d0c88b1 Add vendor assessment agent
Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
2026-04-24 08:43:14 +02:00
Bryan Frimin
ab52dc0a34 Clean agent rules
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-04-19 11:42:50 +02:00
Bryan Frimin
5237e57d27 Revert "Use inline trufflehog:ignore instead of exclude paths file"
This reverts commit f10ecb8210b1176311d9372d1108b91ce8290fd4.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-30 14:18:29 +02:00
Bryan Frimin
7dcc3d21ac Use inline trufflehog:ignore instead of exclude paths file
Inline comments are more targeted than excluding the entire file
from secret scanning. Remove the .trufflehog.yml exclude file and
the --exclude-paths flag from the workflow.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-30 14:18:29 +02:00
Bryan Frimin
4725a1b080 Fix false positives in agent guardrails
Skip empty fingerprints in SystemPromptLeakGuardrail to prevent blank
values from flagging every message. Replace overly broad "sk-" pattern
in SensitiveDataGuardrail with specific LLM provider prefixes
("sk-proj-" for OpenAI, "sk-ant-" for Anthropic) to avoid false
positives on common words like "risk-based" or "task-management".

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-30 14:18:29 +02:00
Bryan Frimin
2f8674471b Fix one-argument-per-line style in prompt injection guardrail
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-30 14:18:29 +02:00
Bryan Frimin
ded859d130 Set temperature to 0 for prompt injection classifier
Deterministic output improves consistency of the safety classifier.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-30 14:18:29 +02:00
Bryan Frimin
ef8402ca93 Add reusable agent guardrails for prompt injection and data leaks
Introduce a pkg/agent/guardrail package with three guardrails that
can be composed into any agent:

- PromptInjectionGuardrail: LLM-based input classifier that detects
  prompt injection attempts before the agent processes them.
- SensitiveDataGuardrail: pattern-based output check for leaked
  tokens, keys, connection strings, and raw SQL.
- SystemPromptLeakGuardrail: configurable output check that detects
  system prompt content in responses using caller-provided
  fingerprints.

The classifier prompt is embedded from a plain text file for easy
review and editing.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-30 14:18:29 +02:00
Bryan Frimin
6a77d42dd6 Style
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-16 00:28:47 +01:00
Bryan Frimin
7a4101185b Add per-folder CLAUDE.md for key packages
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-15 15:04:27 +01:00
Bryan Frimin
5d2b394bac Include error in tool_end event for interrupted tools
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-14 12:28:26 +01:00
Bryan Frimin
d01ee914c1 Style
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 20:00:22 +01:00
Bryan Frimin
deac1538e5 Style
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:58:02 +01:00
Bryan Frimin
d80a0fa7e4 Reject null input in agent tool parameter validation
JSON null unmarshals into an empty string, so the presence-only
key check let {"input":null} through, running the nested agent
with a blank user message.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:57:18 +01:00
Bryan Frimin
9d999559f1 Emit OnToolEnd hooks for interrupted and failed tools
executeSingleTool had three exit paths but only the success path
emitted all end signals. The interrupted path (nested agent
approval) skipped OnToolEnd and StreamEventToolEnd entirely,
leaving hook consumers with an unpaired OnToolStart. The error
path also missed StreamEventToolEnd and AgentHooks.OnToolEnd.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:53:08 +01:00
Bryan Frimin
5c889a1d47 Fall back to StructuredContent in MCP tool results
When an MCP server sets StructuredContent without populating
Content with TextContent entries, extractMCPContent returned
an empty string, making successful tool calls look empty to
the agent. Now the function serializes StructuredContent as
JSON when no text parts are found.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:43:19 +01:00
Bryan Frimin
1f5e68abe6 Fix typeName panic for interface type parameters
reflect.TypeOf on a nil interface value returns nil, causing a
panic when Kind() is called. Use reflect.TypeFor[T]() instead,
which resolves the type directly from the type parameter.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:34:07 +01:00
Bryan Frimin
0c3893ee8b Skip nil handoffs to prevent panic during run
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:31:09 +01:00
Bryan Frimin
cb4b893dfc Skip nil MCP servers in WithMCPServers
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:26:29 +01:00
Bryan Frimin
da9a594f79 Here's a commit message following the repo's style:
Fix Wait draining events from concurrent consumers
Wait() was ranging over the public Events channel, competing
with any concurrent reader for events. Callers that streamed
events in one goroutine and called Wait() in another would
lose an arbitrary subset of events. Wait now only blocks on
the done channel; the result fields are already visible thanks
to the close ordering (set fields → close events → close done).

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 19:22:46 +01:00
Bryan Frimin
f3239a1a7b Return errors from schema generation instead of panicking
jsonSchemaFor panicked on unsupported types, which meant
FunctionTool, NewOutputType, and RunTyped would crash the
process during setup rather than returning a normal error.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 18:56:56 +01:00
Bryan Frimin
def8f417ca Validate required input in agent tool execution
The agentTool.Execute method accepted {} despite the schema
marking input as required. Unlike functionTool, it skipped
required-field validation, silently sending an empty message
to the sub-agent.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 18:31:22 +01:00
Bryan Frimin
9f92a27b51 Emit tool-result for post-handoff tool calls
When the LLM returns tool calls after a handoff in the same
assistant message, they were silently dropped. This left
orphaned tool_call entries without matching tool-result
messages, causing protocol errors on the next LLM turn.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 18:28:37 +01:00
Bryan Frimin
a710a7472d Prevent infinite recursion when agents delegate to each other as tools
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 18:15:45 +01:00
Bryan Frimin
a0ed50a908 Propagate nested agent approval interruptions through tool pipeline
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 18:01:36 +01:00
Bryan Frimin
74f1d44119 Validate required tool parameters before execution
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 17:28:08 +01:00
Bryan Frimin
9fd251ee5d Add agent library
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
2026-03-13 17:21:43 +01:00