-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat: Add SwiftAPI cryptographic attestation for agent governance #4158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
SwiftAPI integration provides cryptographic attestation for all CrewAI tool
invocations and multi-agent orchestration. Every action requires authorization
before execution - no attestation, no execution.
## What this adds
- `SwiftAPIStructuredTool`: Wraps CrewStructuredTool with attestation verification
- `SwiftAPICrew`: Wraps Crew for multi-agent attestation with audit trails
- `SwiftAPIConfig`: Configuration with fail-closed defaults
- Full async support via httpx
- JTI-based audit trail for compliance
## Why this matters
Agentic AI needs governance. SwiftAPI provides:
- Cryptographic proof of authorization (Ed25519 signatures)
- Immutable audit trail (JTI per action)
- Fail-closed execution (no attestation = blocked)
- Policy enforcement before execution, not after
## Usage
```python
from crewai import Crew
from crewai.swiftapi_integration import SwiftAPICrew
crew = Crew(agents=[...], tasks=[...])
swiftapi_crew = SwiftAPICrew(
crew=crew,
swiftapi_key="swiftapi_live_..." # or SWIFTAPI_KEY env var
)
result = swiftapi_crew.kickoff()
```
Tested against live SwiftAPI endpoint. All tests pass.
Get a key: https://getswiftapi.com
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
403 = explicit policy denial. Must never be bypassed regardless of fail_open. Previously, if a 403 response had malformed JSON, response.json() would throw json.JSONDecodeError, falling through to the generic exception handler. With fail_open=True, this would approve an explicitly denied action. Now: JSON parsing errors on 403 responses are caught locally. The denial still raises PolicyViolationError with whatever body text is available. fail_open is for network failures, not explicit denials.
| "User-Agent": "CrewAI-SwiftAPI/1.0", | ||
| }, | ||
| ) | ||
| return self._client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AsyncClient reused across event loops causes runtime errors
The _get_client method stores an httpx.AsyncClient in self._client and reuses it across calls. However, the synchronous wrappers in invoke and _sync_attest use asyncio.run() which creates a temporary event loop that is closed when the call finishes. When the stored AsyncClient is reused in a subsequent asyncio.run() call with a different event loop, it causes "RuntimeError: Event loop is closed" because the client's internal state is bound to the original (now closed) loop. The is_closed check only detects explicit aclose() calls, not event loop closure. This will fail on the second and subsequent synchronous tool invocations or crew kickoffs.
Summary
What this adds
SwiftAPIStructuredToolCrewStructuredToolwith attestation verificationSwiftAPICrewCrewfor multi-agent attestation with audit trailsSwiftAPIConfigMockAttestationProviderWhy this matters
Agentic AI needs governance. SwiftAPI provides:
Usage
Or wrap individual tools:
Test plan
Files
Get a key
https://getswiftapi.com
🤖 Generated with Claude Code
Note
Introduces SwiftAPI-based authorization to gate CrewAI actions before execution, providing auditability (JTIs) and optional tool/crew wrappers.
crewai/swiftapi_integration/withconfig.py,attestation.py,tools.py,crew.py,__init__.py,demo.py, andREADME.txtSwiftAPIStructuredTool: wrapsCrewStructuredToolto call/verifyprior to execution (sync/async), builds intent/context, handles 401/403/429/timeouts, supports shared provider and optionalfail_openSwiftAPICrew: wrapsCrewto attest kickoff (sync/async), optionally wrap all agent tools, and record an audit log with JTI metadataSwiftAPIConfig: env-driven configuration (SWIFTAPI_KEY,SWIFTAPI_URL) with validation and fail-closed defaultsAttestationProvider,SwiftAPIAttestationProvider,MockAttestationProviderfor testingdemo.py: standalone tests for direct API, crew kickoff, and multi-action sequences;README.txtwith usageWritten by Cursor Bugbot for commit 7fbfaaa. This will update automatically on new commits. Configure here.