Building Task Attachments in Astreus
Attach files, images, and data to agent tasks. Process documents, analyze images, work with structured data.
What Are Task Attachments?
Task attachments enable you to attach multiple file types to tasks for comprehensive analysis within the Astreus framework. Instead of manually extracting content or describing files in prompts, you can pass files directly to agents equipped with vision and processing capabilities. This transforms agents from text processors into sophisticated document analyzers.
Getting Started
You can either clone the complete example repository or install the package independently. Both approaches give you access to the task attachment functionality.
Bashgit clone https://github.com/astreus-ai/astreus cd task-attachments npm install
Alternatively, install just the package:
Bashnpm install @astreus-ai/astreus
Create a .env file with your configuration:
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.db
Creating an Agent with Vision
To process attachments, especially images, create an agent with vision capabilities enabled. The vision model handles image analysis while the main model processes text and code.
TypeScriptconst agent = await Agent.create({ name: 'AnalysisAgent', model: 'gpt-4o', visionModel: 'gpt-4o', vision: true });
This configuration enables the agent to process both text-based files and visual content. The vision: true flag activates multimodal processing capabilities.
Attachment Structure
Each attachment requires specific properties to identify and process the file correctly. The type field categorizes the content, while path provides the location and name gives it a display identifier.
TypeScriptconst attachment = { type: 'code', path: './src/auth/login.ts', name: 'Login Controller', language: 'typescript' };
Supported types include code, image, json, and markdown. For code files, specify the language to enable syntax-aware analysis.
Creating Tasks with Multiple Attachments
Tasks accept an array of attachments, allowing you to provide all necessary context in a single request. The agent can reason across different file types simultaneously.
TypeScript
This creates a task that processes code, design mockups, dependencies, and documentation together. The agent analyzes all materials and provides unified insights.
Executing Tasks
Once created, execute tasks by their ID to get the analysis results. The agent processes all attachments and returns a structured response.
TypeScriptconst result = await agent.executeTask(reviewTask.id); console.log('Analysis complete:', result.response);
The execution is asynchronous, allowing you to process multiple tasks concurrently. Results include the agent's analysis of all attached materials.
Running Your Implementation
For cloned repositories, use the provided dev script to run examples:
Bashnpm run dev
For standalone implementations, create an index.ts file with your code and execute with tsx:
Bashpx tsx index.ts
Processing Code Files
Code attachments support language specification for syntax-aware analysis. The agent understands programming constructs and can identify patterns, issues, and improvements.
TypeScript
The language parameter helps the agent apply language-specific best practices and identify common vulnerabilities in that ecosystem.
Image Analysis
Image attachments enable visual analysis when you have design mockups, screenshots, or diagrams. Vision-capable models process these directly without requiring text descriptions.
TypeScript
The agent can identify UI elements, assess layout quality, and provide feedback on visual hierarchy and user experience principles.
Structured Data Processing
JSON attachments are useful for analyzing configuration files, API responses, or structured data. The agent understands the data structure and can validate or extract information.
TypeScript
This enables automated dependency audits, configuration validation, and data quality checks without manual inspection.
Documentation Analysis
Markdown attachments allow you to include documentation, specifications, or written content. The agent can assess completeness, clarity, and accuracy.
TypeScript
The agent understands markdown structure and can identify missing sections, unclear explanations, or inconsistencies in documentation.
Cross-File Analysis
The real power emerges when combining multiple file types in a single task. The agent correlates information across attachments to provide comprehensive insights.
TypeScript
This enables requirement traceability, design-implementation verification, and comprehensive quality assurance in a single operation.
Task Metadata
Metadata helps organize and categorize tasks for filtering, prioritization, and workflow management. Use it to track task types, priorities, or custom classifications.
TypeScriptconst task = await agent.createTask({ prompt: 'Security audit of authentication system', attachments: [/* ... */], metadata: { type: 'security-audit', priority: 'high', component: 'authentication', assignee: 'security-team' } });
Metadata doesn't affect processing but provides context for task management systems and reporting tools.
Best Practices
Keep prompts specific about what to analyze in the attachments. Generic instructions lead to generic results, while focused questions produce actionable insights.
TypeScript
Clear prompts guide the agent's focus and ensure you get relevant, detailed feedback on the aspects that matter most.
When analyzing related files, use descriptive names to help the agent understand relationships. This improves the quality of cross-file analysis.
TypeScript
Descriptive names provide context that helps the agent understand each file's role in the analysis.
Error Handling
Handle task execution errors gracefully to build robust applications. Check for file access issues, format problems, or processing failures.
TypeScript
Proper error handling prevents application crashes and provides clear feedback when attachments can't be processed.
Real-World Use Cases
Task attachments enable sophisticated workflows like automated code reviews. Attach source files and let the agent identify issues, suggest improvements, and verify best practices.
TypeScriptconst codeReview = await agent.createTask({ prompt: 'Comprehensive code review covering security, performance, and maintainability', attachments: [ { type: 'code', path: './src/api/routes.ts', language: 'typescript' }, { type: 'code', path: './src/api/middleware.ts', language: 'typescript' }, { type: 'json', path: './package.json', name: 'Dependencies' } ], metadata: { type: 'code-review', severity: 'standard' } });
This automates repetitive review tasks and ensures consistent quality standards across your codebase.
Design-Implementation Verification
Verify that implementations match design specifications by attaching both design mockups and code. The agent identifies discrepancies and missing features.
TypeScriptconst verification = await agent.createTask({ prompt: 'Verify the implementation matches the approved design', attachments: [ { type: 'image', path: './designs/approved-design.png', name: 'Approved Design' }, { type: 'code', path: './src/components/Feature.tsx', language: 'typescript' }, { type: 'markdown', path: './specs/requirements.md', name: 'Requirements' } ] });
This catches design drift early and ensures the final product matches stakeholder expectations.
Documentation Quality Assurance
Ensure documentation stays synchronized with code by analyzing both together. The agent identifies outdated examples, missing documentation, or incomplete coverage.
TypeScriptconst docCheck = await agent.createTask({ prompt: 'Verify documentation accurately reflects the current API', attachments: [ { type: 'code', path: './src/api/index.ts', language: 'typescript' }, { type: 'markdown', path: './docs/api-guide.md', name: 'API Guide' } ] });
Automated documentation checks maintain quality without manual cross-referencing between docs and code.
Security Audits
Perform security audits by attaching relevant code files and asking the agent to identify vulnerabilities. This complements traditional security tools with contextual analysis.
TypeScriptconst securityAudit = await agent.createTask({ prompt: 'Identify security vulnerabilities including injection attacks, authentication issues, and data exposure', attachments: [ { type: 'code', path: './src/auth/login.ts', language: 'typescript' }, { type: 'code', path: './src/database/queries.ts', language: 'typescript' }, { type: 'json', path: './config/security.json', name: 'Security Config' } ], metadata: { type: 'security-audit', scope: 'authentication' } });
The agent understands security principles and can identify issues that pattern-matching tools might miss.
Working with the Repository
The complete example repository demonstrates all features with runnable code. Explore different attachment types and processing patterns.
Repository: github.com/astreus-ai/astreus
The examples show real-world patterns you can adapt to your specific use cases. Each example includes comments explaining the approach and expected outcomes.
Key Features Summary
Task attachments support diverse file formats including code, images, structured data, and documentation. Language specification enables syntax-aware analysis for code files. Metadata organization facilitates task categorization and workflow management. Integration with vision-capable LLMs enables image processing without manual description.
These capabilities transform agents from text processors into comprehensive document analyzers that understand multiple content types and their relationships.
Future Possibilities
As Astreus evolves, task attachments will support additional file types and larger context windows. Future enhancements may include video processing, audio transcription, and more sophisticated multi-file reasoning. The attachment system provides a foundation for increasingly sophisticated document processing workflows.
This experiment is written for Astreus v0.5.37. Please ensure you are using a compatible version.