Working with Workflow
Workflow in Credo AI consists of two parts: Workflow Stages that define the governance pipeline, and Use Case Workflow that tracks each use case's progress through that pipeline.
Workflow Stages
Workflow stages define the governance pipeline that use cases progress through. The system includes fixed start and end stages, with customizable intermediate stages.
Listing Workflow Stages
- Python
- TypeScript
from credoai import CredoAI
client = CredoAI()
response = client.workflow_stages.list()
for stage in response.items:
print(f"{stage.name} (ID: {stage.id})")
import { createCredoAIClient } from '@credo-ai/sdk';
const client = createCredoAIClient('your-tenant');
const { data: response } = await client.workflowStages.list();
for (const stage of response.items) {
console.log(`${stage.name} (ID: ${stage.id})`);
}
Creating an Intermediate Stage
Only intermediate workflow stages can be created via the API. Start and end stages are system-managed.
- Python
- TypeScript
from credoai import WorkflowStageCreate
stage = client.workflow_stages.create(
data=WorkflowStageCreate(
name="Security Review",
)
)
print(f"Created: {stage.id}")
const { data: stage } = await client.workflowStages.create({
name: 'Security Review',
});
console.log(`Created: ${stage.id}`);
Updating a Stage
Start and end stages cannot be modified via the API.
- Python
- TypeScript
from credoai import WorkflowStageUpdate
updated = client.workflow_stages.update(
workflow_stage_id="ws_abc123",
data=WorkflowStageUpdate(name="Updated Stage Name"),
)
const { data: updated } = await client.workflowStages.update('ws_abc123', {
name: 'Updated Stage Name',
});
Deleting a Stage
Start and end stages cannot be deleted via the API.
- Python
- TypeScript
client.workflow_stages.delete(workflow_stage_id="ws_abc123")
await client.workflowStages.delete('ws_abc123');
Use Case Workflow
Each use case has a workflow that tracks its progress through the governance pipeline. The workflow has both a current stage and a current step within that stage.
Step progression within each stage: assessment -> evidence_collection -> clear
Getting Workflow Status
- Python
- TypeScript
use_case = client.use_cases("uc_abc123")
workflow = use_case.workflow.get()
print(f"Current stage: {workflow.stage}")
print(f"Current step: {workflow.step}")
const { data: workflow } = await client.useCases.workflow.get('uc_abc123');
console.log(`Current stage: ${workflow.stage}`);
console.log(`Current step: ${workflow.step}`);
Updating Workflow
- Python
- TypeScript
from credoai import UseCaseWorkflowUpdate
use_case = client.use_cases("uc_abc123")
updated = use_case.workflow.update(
data=UseCaseWorkflowUpdate(stage_id="ws_abc123"),
)
const { data: updated } = await client.useCases.workflow.update('uc_abc123', {
stageId: 'ws_abc123',
});
Advancing the Step
Move to the next step within the current workflow stage:
- Python
- TypeScript
use_case = client.use_cases("uc_abc123")
# Advance: assessment -> evidence_collection -> clear
result = use_case.workflow.advance_step()
print(f"New step: {result.step}")
// Advance: assessment -> evidence_collection -> clear
const { data: result } = await client.useCases.workflow.advanceStep('uc_abc123');
console.log(`New step: ${result.step}`);
Advancing the Stage
Move to the next workflow stage, resetting to the assessment step:
- Python
- TypeScript
use_case = client.use_cases("uc_abc123")
result = use_case.workflow.advance_stage()
print(f"New stage: {result.stage}")
const { data: result } = await client.useCases.workflow.advanceStage('uc_abc123');
console.log(`New stage: ${result.stage}`);
Rejecting a Use Case
Set the use case's workflow step to rejected. This is a terminal state.
- Python
- TypeScript
use_case = client.use_cases("uc_abc123")
result = use_case.workflow.reject()
print(f"Step: {result.step}") # "rejected"
const { data: result } = await client.useCases.workflow.reject('uc_abc123');
console.log(`Step: ${result.step}`); // "rejected"
Next Steps
- Learn about Use Cases as the primary governed resource
- Explore Policy Packs for governance controls
- See the Workflow Stages API Reference and Use Case Workflow API Reference