Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
840 changes: 840 additions & 0 deletions typescript/.kiro/specs/anp-typescript-sdk/design.md

Large diffs are not rendered by default.

154 changes: 154 additions & 0 deletions typescript/.kiro/specs/anp-typescript-sdk/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Requirements Document

## Introduction

This document defines the requirements for developing a TypeScript SDK for the Agent Network Protocol (ANP). The SDK will enable developers to build ANP-compliant agents with support for identity authentication (did:wba), agent description (ADP), agent discovery (ADSP), and meta-protocol negotiation. The SDK will use XState v5 for state machine management to handle complex protocol flows and state transitions.

**IMPORTANT**: All SDK code MUST be developed in a new `ts_sdk` directory at the root of the project. This directory will contain the complete TypeScript SDK implementation including source code, tests, configuration files, and documentation.

## Glossary

- **ANP_SDK**: The TypeScript Software Development Kit for implementing Agent Network Protocol functionality, located in the `ts_sdk` directory
- **ts_sdk_Directory**: The root directory containing all SDK source code, tests, and configuration files
- **Agent**: An autonomous software entity that can communicate and collaborate with other agents using ANP
- **DID_WBA**: Web-Based Agent Decentralized Identifier method for cross-platform identity authentication
- **ADP**: Agent Description Protocol for publishing agent capabilities and interfaces
- **ADSP**: Agent Discovery Service Protocol for discovering agents in the network
- **Meta_Protocol**: Protocol negotiation mechanism for agents to dynamically agree on communication protocols
- **State_Machine**: XState v5 state machine for managing protocol flows and transitions
- **HTTP_Client**: HTTP client for making requests to other agents and services
- **Crypto_Module**: Cryptographic module for signing, verification, and encryption operations

## Requirements

### Requirement 1: DID:WBA Identity Management

**User Story:** As an agent developer, I want to create and manage DID:WBA identities, so that my agent can authenticate with other agents across platforms.

#### Acceptance Criteria

1. WHEN the developer creates a new DID:WBA identity, THE ANP_SDK SHALL generate a key pair and create a DID document conforming to the did:wba specification
2. WHEN the developer provides a domain and path, THE ANP_SDK SHALL construct a valid did:wba identifier following the format "did:wba:domain:path"
3. WHEN the developer requests to sign data, THE ANP_SDK SHALL use the private key to generate a signature and return the signature value
4. WHEN the developer provides a DID identifier, THE ANP_SDK SHALL resolve the DID document from the appropriate HTTPS endpoint
5. WHEN the developer provides signature data and a DID document, THE ANP_SDK SHALL verify the signature using the public key from the verification method

### Requirement 2: HTTP Authentication with DID:WBA

**User Story:** As an agent developer, I want to authenticate HTTP requests using DID:WBA, so that my agent can securely communicate with other agents.

#### Acceptance Criteria

1. WHEN the agent makes an initial HTTP request to another agent, THE ANP_SDK SHALL include the Authorization header with DID, nonce, timestamp, verification_method, and signature
2. WHEN the agent receives an HTTP request with DID:WBA authentication, THE ANP_SDK SHALL resolve the client DID document and verify the signature
3. WHEN signature verification succeeds, THE ANP_SDK SHALL generate an access token and return it to the client
4. WHEN the agent makes subsequent requests, THE ANP_SDK SHALL include the access token in the Authorization header
5. WHEN the agent receives a request with an access token, THE ANP_SDK SHALL validate the token and grant access if valid

### Requirement 3: Agent Description Management

**User Story:** As an agent developer, I want to create and publish agent description documents, so that other agents can discover my agent's capabilities and interfaces.

#### Acceptance Criteria

1. WHEN the developer provides agent metadata, THE ANP_SDK SHALL generate an ADP-compliant JSON-LD document with required fields
2. WHEN the developer adds information resources, THE ANP_SDK SHALL include them in the Infomations array with type, description, and url
3. WHEN the developer adds interfaces, THE ANP_SDK SHALL include them in the interfaces array with type, protocol, version, and url
4. WHEN the developer requests to sign the agent description, THE ANP_SDK SHALL generate a proof object with digital signature
5. WHEN the developer provides an agent description URL, THE ANP_SDK SHALL fetch and parse the agent description document

### Requirement 4: Agent Discovery

**User Story:** As an agent developer, I want to discover other agents in the network, so that my agent can find and interact with relevant services.

#### Acceptance Criteria

1. WHEN the developer provides a domain name, THE ANP_SDK SHALL fetch the agent discovery document from the .well-known/agent-descriptions endpoint
2. WHEN the discovery document contains pagination, THE ANP_SDK SHALL recursively fetch all pages until no next property exists
3. WHEN the developer registers with a search service, THE ANP_SDK SHALL send a registration request with the agent description URL
4. WHEN the developer searches for agents, THE ANP_SDK SHALL query the search service and return matching agent descriptions
5. WHEN the discovery process encounters errors, THE ANP_SDK SHALL handle errors gracefully and return appropriate error messages

### Requirement 5: Meta-Protocol Negotiation State Machine

**User Story:** As an agent developer, I want to negotiate communication protocols dynamically, so that my agent can communicate efficiently with heterogeneous agents.

#### Acceptance Criteria

1. WHEN the agent initiates protocol negotiation, THE State_Machine SHALL transition to the negotiating state and send a protocolNegotiation message
2. WHEN the agent receives a negotiation response, THE State_Machine SHALL process the candidateProtocols and determine whether to accept or continue negotiating
3. WHEN both agents agree on a protocol, THE State_Machine SHALL transition to the codeGeneration state
4. WHEN code generation completes, THE State_Machine SHALL send a codeGeneration message with status "generated"
5. WHEN the negotiation exceeds the maximum rounds, THE State_Machine SHALL transition to the rejected state and terminate negotiation

### Requirement 6: Application Protocol Communication

**User Story:** As an agent developer, I want to send and receive application protocol messages, so that my agent can exchange data with other agents using negotiated protocols.

#### Acceptance Criteria

1. WHEN the agent sends an application message, THE ANP_SDK SHALL construct a message with protocol type 01 and the application data
2. WHEN the agent receives an application message, THE ANP_SDK SHALL parse the protocol data according to the negotiated protocol
3. WHEN the agent sends a natural language message, THE ANP_SDK SHALL construct a message with protocol type 10 and UTF-8 encoded text
4. WHEN the agent receives a natural language message, THE ANP_SDK SHALL decode the UTF-8 text and pass it to the application
5. WHEN message processing fails, THE ANP_SDK SHALL generate appropriate error messages and handle the failure gracefully

### Requirement 7: End-to-End Encryption

**User Story:** As an agent developer, I want to encrypt messages end-to-end, so that my agent's communications remain private even through intermediaries.

#### Acceptance Criteria

1. WHEN the agent initiates encrypted communication, THE Crypto_Module SHALL perform ECDHE key exchange using the recipient's keyAgreement public key
2. WHEN the shared secret is established, THE Crypto_Module SHALL derive encryption keys using a key derivation function
3. WHEN the agent sends a message, THE Crypto_Module SHALL encrypt the message data using the derived encryption key
4. WHEN the agent receives an encrypted message, THE Crypto_Module SHALL decrypt the message using the shared secret
5. WHEN encryption or decryption fails, THE Crypto_Module SHALL return an error and prevent message processing

### Requirement 8: Test Cases Negotiation

**User Story:** As an agent developer, I want to negotiate test cases with other agents, so that protocol implementations can be verified before production use.

#### Acceptance Criteria

1. WHEN the agent proposes test cases, THE State_Machine SHALL send a testCasesNegotiation message with test case descriptions
2. WHEN the agent receives test case proposals, THE State_Machine SHALL evaluate the test cases and respond with acceptance or modifications
3. WHEN both agents agree on test cases, THE State_Machine SHALL execute the test cases and verify the results
4. WHEN test execution fails, THE State_Machine SHALL send a fixErrorNegotiation message with error descriptions
5. WHEN all tests pass, THE State_Machine SHALL transition to the ready state for production communication

### Requirement 9: Error Handling and Recovery

**User Story:** As an agent developer, I want robust error handling, so that my agent can recover from failures and continue operating.

#### Acceptance Criteria

1. WHEN network errors occur, THE ANP_SDK SHALL retry the request with exponential backoff up to a maximum number of attempts
2. WHEN DID resolution fails, THE ANP_SDK SHALL return a descriptive error message indicating the resolution failure
3. WHEN signature verification fails, THE ANP_SDK SHALL reject the request and return an authentication error
4. WHEN protocol negotiation fails, THE State_Machine SHALL transition to the rejected state and notify the application
5. WHEN unexpected errors occur, THE ANP_SDK SHALL log the error details and provide a generic error response

### Requirement 10: Configuration and Extensibility

**User Story:** As an agent developer, I want to configure the SDK behavior, so that I can customize it for my specific use case.

#### Acceptance Criteria

1. WHEN the developer initializes the SDK, THE ANP_SDK SHALL accept configuration options for timeouts, retry policies, and endpoints
2. WHEN the developer registers custom protocol handlers, THE ANP_SDK SHALL use the custom handlers for processing specific protocol types
3. WHEN the developer provides custom cryptographic implementations, THE ANP_SDK SHALL use the custom implementations instead of defaults
4. WHEN the developer enables debug mode, THE ANP_SDK SHALL log detailed information about protocol flows and state transitions
5. WHEN the developer extends the SDK with plugins, THE ANP_SDK SHALL load and execute the plugins at appropriate lifecycle hooks

### Requirement 11: Test-Driven Development Support

**User Story:** As an agent developer, I want comprehensive test coverage, so that I can trust the SDK implementation and ensure protocol compliance.

#### Acceptance Criteria

1. WHEN implementing any SDK feature, THE ANP_SDK SHALL have unit tests written before the implementation code
2. WHEN testing DID operations, THE ANP_SDK SHALL include tests for key generation, signing, verification, and DID resolution
3. WHEN testing protocol negotiation, THE ANP_SDK SHALL include tests for all state transitions and edge cases
4. WHEN testing HTTP authentication, THE ANP_SDK SHALL include tests for both successful and failed authentication scenarios
5. WHEN running the test suite, THE ANP_SDK SHALL achieve at least 80% code coverage across all modules
Loading