discovery

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package discovery implements gossip-based agent card propagation and peer discovery.

Index

Constants

View Source
const TopicAgentCard = "/lango/agentcard/1.0.0"

TopicAgentCard is the GossipSub topic for agent card propagation.

Variables

This section is empty.

Functions

func PeerIDFromString

func PeerIDFromString(s string) (peer.ID, error)

PeerIDFromString parses a peer ID string.

Types

type AdService

type AdService struct {
	// contains filtered or unexported fields
}

AdService manages agent advertisement and discovery via DHT provider records.

func NewAdService

func NewAdService(cfg AdServiceConfig) *AdService

NewAdService creates a new agent advertisement service.

func (*AdService) Advertise

func (s *AdService) Advertise(ctx context.Context) error

Advertise publishes the local agent ad to the DHT.

func (*AdService) Discover

func (s *AdService) Discover(ctx context.Context, tags []string) ([]*AgentAd, error)

Discover searches for agent ads matching the given tags.

func (*AdService) DiscoverByCapability

func (s *AdService) DiscoverByCapability(ctx context.Context, capability string) []*AgentAd

DiscoverByCapability returns ads matching a specific capability.

func (*AdService) StoreAd

func (s *AdService) StoreAd(ad *AgentAd) error

StoreAd stores a discovered agent ad after ZK credential verification.

type AdServiceConfig

type AdServiceConfig struct {
	DHT      *dht.IpfsDHT
	LocalAd  *AgentAd
	Verifier ZKCredentialVerifier
	Logger   *zap.SugaredLogger
}

AdServiceConfig configures the AdService.

type AgentAd

type AgentAd struct {
	DID           string            `json:"did"`
	Name          string            `json:"name"`
	Description   string            `json:"description"`
	Tags          []string          `json:"tags"`
	Capabilities  []string          `json:"capabilities,omitempty"`
	Pricing       *PricingInfo      `json:"pricing,omitempty"`
	ZKCredentials []ZKCredential    `json:"zkCredentials,omitempty"`
	Multiaddrs    []string          `json:"multiaddrs,omitempty"`
	PeerID        string            `json:"peerId"`
	Timestamp     time.Time         `json:"timestamp"`
	Metadata      map[string]string `json:"metadata,omitempty"`
}

AgentAd is a structured service advertisement (Context Flyer).

type GossipCard

type GossipCard struct {
	Name          string         `json:"name"`
	Description   string         `json:"description"`
	DID           string         `json:"did,omitempty"`
	Multiaddrs    []string       `json:"multiaddrs,omitempty"`
	Capabilities  []string       `json:"capabilities,omitempty"`
	Pricing       *PricingInfo   `json:"pricing,omitempty"`
	ZKCredentials []ZKCredential `json:"zkCredentials,omitempty"`
	PeerID        string         `json:"peerId"`
	Timestamp     time.Time      `json:"timestamp"`
}

GossipCard is an agent card propagated via GossipSub.

type GossipConfig

type GossipConfig struct {
	Host      host.Host
	LocalCard *GossipCard
	Interval  time.Duration
	Verifier  ZKCredentialVerifier
	Logger    *zap.SugaredLogger
}

GossipConfig configures the gossip service.

type GossipService

type GossipService struct {
	// contains filtered or unexported fields
}

GossipService manages agent card propagation via GossipSub.

func NewGossipService

func NewGossipService(cfg GossipConfig) (*GossipService, error)

NewGossipService creates a new gossip-based discovery service.

func (*GossipService) FindByCapability

func (g *GossipService) FindByCapability(capability string) []*GossipCard

FindByCapability returns peers that advertise the given capability.

func (*GossipService) FindByDID

func (g *GossipService) FindByDID(did string) *GossipCard

FindByDID returns a peer by DID.

func (*GossipService) IsRevoked

func (g *GossipService) IsRevoked(did string) bool

IsRevoked checks if a DID has been revoked.

func (*GossipService) KnownPeers

func (g *GossipService) KnownPeers() []*GossipCard

KnownPeers returns all known peer agent cards.

func (*GossipService) RevokeDID

func (g *GossipService) RevokeDID(did string)

RevokeDID marks a DID as revoked, preventing its credentials from being accepted.

func (*GossipService) SetMaxCredentialAge

func (g *GossipService) SetMaxCredentialAge(d time.Duration)

SetMaxCredentialAge sets the maximum allowed age for ZK credentials.

func (*GossipService) Start

func (g *GossipService) Start(wg *sync.WaitGroup)

Start begins periodic card publication and message processing.

func (*GossipService) Stop

func (g *GossipService) Stop()

Stop halts the gossip service.

type PricingInfo

type PricingInfo struct {
	Currency   string            `json:"currency"`   // e.g. "USDC"
	PerQuery   string            `json:"perQuery"`   // per-query price
	PerMinute  string            `json:"perMinute"`  // per-minute price
	ToolPrices map[string]string `json:"toolPrices"` // per-tool pricing
}

PricingInfo describes the pricing for an agent's services.

type ZKCredential

type ZKCredential struct {
	CapabilityID string    `json:"capabilityId"`
	Proof        []byte    `json:"proof"`
	IssuedAt     time.Time `json:"issuedAt"`
	ExpiresAt    time.Time `json:"expiresAt"`
}

ZKCredential is a zero-knowledge proof of agent capability.

type ZKCredentialVerifier

type ZKCredentialVerifier func(cred *ZKCredential) (bool, error)

ZKCredentialVerifier verifies a ZK credential proof.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL