stemedb/sdk/go/adk/tools_query.go
jordan b3e8a9a058 feat: Multi-application expansion with chaos testing and community UI
Major additions:
- Community Next.js app (port 18187) for browsing claims with API docs
- stemedb-chaos crate: Fault injection, chaos testing, CRDT properties
- Latent ingestion system: Reddit/FDA ingesters with ADK-Go agents
- Disputed claims handling: Manual review workflows and validation
- Aphoria security scanner: New extractors (SQL injection, command
  injection, weak crypto, TLS version), policy-based ignores, UAT reports
- Docker infrastructure: Dockerfile, docker-compose.yml for full stack
- VulnBank demo: Intentionally vulnerable multi-language test corpus

SDK & API enhancements:
- Source registry handlers for tracking data provenance
- Metrics endpoint
- Skeptic filtering improvements

Code quality:
- Split 14 large files (>500 lines) into focused modules
- All files now under 500-line limit per project guidelines

Documentation:
- Chaos testing guide, circuit breakers, observability docs
- Phase 7 UAT documentation updates
- Martin Kleppmann technical writer agent

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 01:24:14 -07:00

84 lines
2.0 KiB
Go

package adk
import (
"context"
"encoding/json"
"fmt"
"github.com/orchard9/stemedb-go/steme"
)
// QueryTool provides lens-based knowledge retrieval.
//
// Used by all agents to retrieve current knowledge with conflict resolution.
type QueryTool struct {
client EpistemeClient
}
// NewQueryTool creates a new Query tool.
func NewQueryTool(client EpistemeClient) *QueryTool {
return &QueryTool{client: client}
}
// Name returns the tool name.
func (t *QueryTool) Name() string {
return "episteme_query"
}
// Description returns the tool description.
func (t *QueryTool) Description() string {
return "Query Episteme knowledge graph with lens-based conflict resolution. " +
"Returns resolved value with confidence score and source provenance. " +
"CRITICAL: Always filter by lifecycle=approved for production decisions."
}
// Execute performs the query operation.
func (t *QueryTool) Execute(ctx context.Context, input []byte) ([]byte, error) {
var params QueryInput
if err := json.Unmarshal(input, &params); err != nil {
return nil, fmt.Errorf("invalid query input: %w", err)
}
// Build StemeDB query params
builder := steme.NewQuery()
if params.Subject != "" {
builder.WithSubject(params.Subject)
}
if params.Predicate != "" {
builder.WithPredicate(params.Predicate)
}
if params.Lens != "" {
lens := parseLen(params.Lens)
builder.WithLens(lens)
}
if params.Lifecycle != "" {
lifecycle := parseLifecycle(params.Lifecycle)
builder.WithLifecycle(lifecycle)
}
// Execute query
result, err := t.client.Query(ctx, builder.Build())
if err != nil {
errorOutput, marshalErr := json.Marshal(QueryOutput{
Error: err.Error(),
})
if marshalErr != nil {
return nil, fmt.Errorf("query failed: %w", err)
}
return errorOutput, nil
}
// Convert to QueryOutput format
output := convertQueryResult(result, params.MinConfidence)
outputBytes, err := json.Marshal(output)
if err != nil {
return nil, fmt.Errorf("failed to marshal query output: %w", err)
}
return outputBytes, nil
}