Context Sources
Context sources allow you to fetch and inject content from external systems into agent prompts. Radium supports multiple source protocols for flexible context gathering.
Overviewβ
Context sources enable agents to access information from:
- Local Files: File system files via
file://URIs - HTTP/HTTPS: Web resources via
http://andhttps://URIs - Jira: Jira issues and projects via
jira://URIs - Braingrid: Braingrid requirements and tasks via
braingrid://URIs
Local File Sourcesβ
Local file sources use the file:// protocol to read files from the file system.
Basic Usageβ
let reader = LocalFileReader::with_base_dir(&workspace_root);
let content = reader.fetch("file:///path/to/file.txt").await?;
In ContextManagerβ
Local file sources are automatically registered and used when building context:
let manager = ContextManager::new(&workspace);
let context = manager.build_context("agent[input:file:///path/to/file.md]", None)?;
File URIs in injection syntax are automatically resolved:
rad step agent[input:file:///absolute/path/to/file.md]
HTTP/HTTPS Sourcesβ
HTTP sources allow fetching content from web resources.
Basic Usageβ
let reader = HttpReader::new();
let metadata = reader.verify("https://example.com/document.md").await?;
let content = reader.fetch("https://example.com/document.md").await?;
In ContextManagerβ
HTTP sources are automatically available:
// Fetch content from HTTP source
let context = manager.build_context(
"agent[input:https://api.example.com/spec.json]",
None
)?;
Error Handlingβ
HTTP sources handle common errors:
- Network timeouts
- HTTP errors (404, 500, etc.)
- SSL certificate errors
- Size limits (default: 10MB)
Jira Sourcesβ
Jira sources fetch content from Jira issues using the jira:// protocol.
URI Formatβ
jira://<project-key>-<issue-number>
Examples:
jira://PROJ-123- Issue PROJ-123jira://REQ-456- Issue REQ-456
Authenticationβ
Jira sources require authentication credentials configured in your workspace:
# .radium/config.toml
[auth.jira]
username = "user@example.com"
api_token = "your-api-token"
# or
password = "your-password"
Basic Usageβ
let reader = JiraReader::new();
let content = reader.fetch("jira://PROJ-123").await?;
In ContextManagerβ
let context = manager.build_context(
"agent[input:jira://PROJ-123]",
None
)?;
Braingrid Sourcesβ
Braingrid sources fetch requirements and tasks from Braingrid using the braingrid:// protocol.
URI Formatβ
braingrid://<node-id>
Examples:
braingrid://REQ-69- Requirement REQ-69braingrid://TASK-1- Task TASK-1
Authenticationβ
Braingrid sources use the braingrid CLI tool for authentication. Ensure you're logged in:
braingrid auth login
Basic Usageβ
let reader = BraingridReader::new();
let content = reader.fetch("braingrid://REQ-69").await?;
In ContextManagerβ
let context = manager.build_context(
"agent[input:braingrid://REQ-69]",
None
)?;
Source Registryβ
The Source Registry automatically routes URIs to the correct reader based on the URI scheme.
Automatic Registrationβ
All source readers are automatically registered in ContextManager:
let manager = ContextManager::new(&workspace);
// SourceRegistry is initialized with all readers:
// - LocalFileReader
// - HttpReader
// - JiraReader
// - BraingridReader
Manual Registrationβ
You can manually register custom readers:
use radium_core::context::sources::{SourceRegistry, SourceReader};
let mut registry = SourceRegistry::new();
registry.register(Box::new(MyCustomReader::new()));
URI Routingβ
The registry automatically routes URIs:
file://...β LocalFileReaderhttp://...orhttps://...β HttpReaderjira://...β JiraReaderbraingrid://...β BraingridReader
Source Verificationβ
Before fetching, you can verify a source is accessible:
let metadata = reader.verify("https://example.com/doc.md").await?;
if metadata.accessible {
let content = reader.fetch("https://example.com/doc.md").await?;
}
Verification Resultsβ
SourceMetadata includes:
- accessible: Whether the source is reachable
- size: Content size in bytes (if available)
- last_modified: Last modification time (if available)
Error Handlingβ
All source readers return consistent errors:
- InvalidUri: URI format is invalid
- NotFound: Source doesn't exist or is inaccessible
- NetworkError: Network request failed
- AuthenticationError: Authentication failed (Jira, Braingrid)
Example Error Handlingβ
match reader.fetch(&uri).await {
Ok(content) => {
// Use content
}
Err(SourceError::NotFound(_)) => {
// Source doesn't exist
}
Err(SourceError::AuthenticationError(_)) => {
// Need to authenticate
}
Err(e) => {
// Other error
}
}
Best Practicesβ
Source Reliabilityβ
- Use local files for critical context (most reliable)
- HTTP sources may be unavailable (handle errors gracefully)
- Jira/Braingrid require authentication (configure credentials)
Performanceβ
- Sources are fetched asynchronously
- HTTP sources have a 10MB size limit by default
- Cache content locally if fetching repeatedly
Securityβ
- Don't expose sensitive credentials in URIs
- Use environment variables or config files for authentication
- Verify SSL certificates for HTTPS sources
Troubleshootingβ
HTTP Source Failsβ
- Check network connectivity
- Verify URL is correct and accessible
- Check for SSL certificate issues
- Verify size limits aren't exceeded
Jira Source Failsβ
- Verify credentials in
.radium/config.toml - Check Jira URL is accessible
- Verify API token has read permissions
- Check issue key format is correct
Braingrid Source Failsβ
- Ensure
braingridCLI is installed and in PATH - Verify you're logged in:
braingrid auth status - Check project ID is correct
- Verify node ID exists in Braingrid