# Output Overview

####

The **Axion Framework** provides a robust and extensible mechanism for managing and generating outputs from various components. Outputs include task results, decision logs, knowledge graphs, and decentralized data reports. This section explains how outputs are handled, stored, and utilized within the framework.

***

#### Key Output Types

**1. Task Results**\
Task results generated by agents can be stored locally, logged on the blockchain, or uploaded to IPFS for decentralized access.\
Examples of task results:

* Text analyses or summaries
* Images or visual data
* Computation outcomes

***

**2. Swarm Consensus Logs**\
Outputs from swarm decision-making processes are logged for auditing and transparency.\
Includes:

* Task proposals
* Voting results
* Final consensus decisions

***

**3. Knowledge Graphs**\
Visual representations of relationships and entities stored in the knowledge graph.\
Exportable as:

* Graph image files (e.g., `.png`, `.jpg`)
* Data files (`.json`, `.csv`) for external analysis

***

**4. Decentralized Reports**\
Reports or datasets are generated by agents and uploaded to IPFS for secure, distributed access.\
Reports may include:

* Performance metrics
* Workflow execution summaries

***

**5. Blockchain Logs**\
Task and decision logs are recorded on-chain for transparency and verification.\
Includes:

* Task descriptions and results
* Transaction hashes for on-chain actions

***

#### Examples

**1. Saving Task Results**\
Agents can save results locally or upload them to IPFS for decentralized storage.

```python
# Save task results locally
task_result = "AI successfully analyzed the dataset."
with open("results/task_result.txt", "w") as file:
    file.write(task_result)

# Upload task results to IPFS
from src.utils.ipfs_client import IPFSClient
ipfs_client = IPFSClient()
cid = ipfs_client.upload_file("results/task_result.txt")
print(f"Task result uploaded to IPFS with CID: {cid}")
```

***

**2. Logging Consensus Decisions**\
Swarm decisions can be saved for transparency and further analysis.

```python
from src.swarm.swarm_consensus import SwarmConsensus
swarm = SwarmConsensus(agent_id=1)

# Propose and log a task
proposal_id = swarm.propose_task("Optimize AI model training")
consensus = swarm.get_consensus()
if consensus:
    print(f"Consensus reached for proposal: {consensus}")
    with open("logs/consensus_log.txt", "a") as log_file:
        log_file.write(f"Proposal {proposal_id} reached consensus: {consensus}\n")
```

***

**3. Exporting Knowledge Graphs**\
Visualize and export knowledge graphs for insights into agent knowledge.

```python
from src.utils.knowledge_graph import KnowledgeGraph

# Initialize and add data to the knowledge graph
knowledge_graph = KnowledgeGraph()
knowledge_graph.add_concept("AI Agent", {"role": "worker"})
knowledge_graph.add_relationship("AI Agent", "Swarm", "belongs_to")

# Save the knowledge graph as an image
knowledge_graph.visualize_graph(output_path="outputs/knowledge_graph.png")

# Export the graph data as JSON
knowledge_graph.export_to_json("outputs/knowledge_graph.json")
```

***

**4. Generating Decentralized Reports**\
Upload reports to IPFS for secure, distributed access.

```python
# Generate a decentralized report
report_content = {
    "task": "Data analysis",
    "result": "Successful",
    "timestamp": "2024-12-28T12:00:00Z"
}

# Save the report locally
import json
with open("outputs/report.json", "w") as file:
    json.dump(report_content, file)

# Upload the report to IPFS
cid = ipfs_client.upload_file("outputs/report.json")
print(f"Report uploaded to IPFS with CID: {cid}")
```

***

**5. Blockchain Task Logs**\
Log tasks and results on the blockchain for immutable tracking.

```python
from src.utils.blockchain_manager import BlockchainManager

# Initialize the Blockchain Manager
blockchain = BlockchainManager()

# Log a task on the blockchain
task_description = "Analyze solar energy consumption trends."
task_result = "Task completed successfully."
transaction_hash = blockchain.log_task(
    sender_keypair="path/to/solana_wallet.json",
    task_description=task_description,
    task_result=task_result
)
print(f"Task logged on blockchain. Transaction hash: {transaction_hash}")
```

***

#### Best Practices for Managing Outputs

**File Management**

* Use structured directories (e.g., `outputs/`, `logs/`) for organized data storage.
* Standardize file names and formats for consistency.

**Decentralization**

* Use IPFS to ensure sensitive data is securely stored and available.
* Leverage blockchain for immutable task logs.

**Data Privacy**

* Encrypt sensitive outputs before storage or upload.
* Use private IPFS gateways for controlled access.

**Auditability**

* Maintain detailed logs for debugging, compliance, and reporting.
* Record all task results, consensus decisions, and on-chain activities.

***

#### Common Issues and Solutions

| Issue                                        | Solution                                                                    |
| -------------------------------------------- | --------------------------------------------------------------------------- |
| FileNotFoundError: Missing outputs directory | Create the directory before saving outputs (`mkdir outputs`).               |
| IPFS upload failure                          | Check IPFS client connectivity and retry.                                   |
| Blockchain log failure                       | Ensure sufficient balance for transaction fees and verify RPC connectivity. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://axions-organization.gitbook.io/axion-framework/output-overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
