71 lines
2.5 KiB
C++
71 lines
2.5 KiB
C++
#pragma once
|
|
|
|
// bedrock-agent-runtime (host bedrock-agent-runtime.<region>.amazonaws.com):
|
|
// InvokeAgent (event stream) and knowledge base Retrieve. This host takes SigV4
|
|
// only; Bedrock API keys are refused before any traffic.
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
#include "vendors/bedrock/client.h"
|
|
#include "vendors/bedrock/control.h"
|
|
|
|
namespace molo::bedrock {
|
|
|
|
struct AgentInvokeParams {
|
|
std::string agent_id; // [0-9a-zA-Z]{1,10}
|
|
std::string alias_id; // [0-9a-zA-Z]{1,10}
|
|
std::string session_id; // [0-9a-zA-Z._:-]{2,100}
|
|
std::string input_text; // up to 25,000,000 characters
|
|
bool enable_trace = false;
|
|
bool end_session = false;
|
|
std::string memory_id; // optional, same pattern as the session id
|
|
Json session_state = Json::object(); // sessionState passthrough, optional
|
|
bool stream_final_response = false; // streamingConfigurations.streamFinalResponse
|
|
void validate() const;
|
|
Json to_json() const;
|
|
};
|
|
|
|
struct AgentResult {
|
|
std::string text;
|
|
std::string session_id;
|
|
std::size_t chunks = 0;
|
|
Json traces = Json::array(); // trace events, capped
|
|
Json return_control = Json(); // returnControl payload when the agent asks the caller to act
|
|
Json attributions = Json::array();
|
|
bool traces_truncated = false;
|
|
};
|
|
|
|
struct RetrieveParams {
|
|
std::string knowledge_base_id; // [0-9a-zA-Z]{10}
|
|
std::string query; // 1..20000 characters
|
|
int number_of_results = 0; // 0: service default, else 1..100
|
|
std::string search_type; // "" | HYBRID | SEMANTIC
|
|
Json filter; // optional RetrievalFilter union, passthrough
|
|
std::string next_token;
|
|
std::string guardrail_id, guardrail_version;
|
|
void validate() const;
|
|
Json to_json() const;
|
|
};
|
|
|
|
struct RetrieveResult {
|
|
Json results = Json::array(); // retrievalResults
|
|
std::string next_token;
|
|
std::string guardrail_action;
|
|
bool truncated = false; // only set by retrieve_all
|
|
std::size_t pages = 0;
|
|
};
|
|
|
|
class AgentRuntime : public BedrockService {
|
|
public:
|
|
using BedrockService::BedrockService;
|
|
// on_text gets each decoded text chunk; return false to stop. Costs money.
|
|
AgentResult invoke_agent(const AgentInvokeParams& params,
|
|
const std::function<bool(const std::string&)>& on_text = nullptr);
|
|
RetrieveResult retrieve(const RetrieveParams& params);
|
|
// Follows nextToken up to `max_pages` (<= BedrockCaps::kMaxPages) pages.
|
|
RetrieveResult retrieve_all(RetrieveParams params, std::size_t max_pages);
|
|
};
|
|
|
|
} // namespace molo::bedrock
|