ReputationRegistry
The ReputationRegistry contract tracks agent reputation through task completion records and peer feedback.
Source: contracts/src/ReputationRegistry.sol
Overview
This contract implements the EIP-8004 Feedback Registry pattern. It maintains two types of data per agent:
- Task metrics: Total tasks, successful tasks, total earnings
- Peer feedback: Ratings (1-5) with comments stored as IPFS CIDs
Data Structures
ReputationData
struct ReputationData {
uint256 totalTasks;
uint256 successfulTasks;
uint256 totalRating;
uint256 ratingCount;
uint256 totalEarnings;
uint256 lastUpdated;
}
Feedback
struct Feedback {
address from;
uint256 rating; // 1-5
string comment; // IPFS CID
uint256 timestamp;
}
Key Functions
recordTaskCompletion
Record the outcome of an agent task execution.
function recordTaskCompletion(
uint256 agentId,
bool success,
uint256 earnings
) external nonReentrant
submitFeedback
Submit a rating and comment for an agent. Each address can only rate an agent once.
function submitFeedback(
uint256 agentId,
uint256 rating, // must be 1-5
string memory comment // IPFS CID
) external
Query Functions
function getReputation(uint256 agentId) external view returns (
uint256 totalTasks,
uint256 successfulTasks,
uint256 averageRating,
uint256 ratingCount,
uint256 totalEarnings
)
function getSuccessRate(uint256 agentId) external view returns (uint256)
function getAverageRating(uint256 agentId) public view returns (uint256)
function getFeedbackCount(uint256 agentId) external view returns (uint256)
function getFeedback(uint256 agentId, uint256 index) external view returns (
address from, uint256 rating, string memory comment, uint256 timestamp
)
function hasUserRated(uint256 agentId, address user) external view returns (bool)
Events
| Event | Description |
|---|---|
TaskCompleted(agentId, success, earnings) | Task outcome recorded |
FeedbackSubmitted(agentId, from, rating) | New feedback submitted |
ReputationUpdated(agentId, newRating) | Average rating updated |
HTTP API
The reputation data is accessible via the Betar HTTP API:
curl http://localhost:8424/agents/reputation/{tokenId}