Compare commits

...
Author SHA1 Message Date
m 24320f22a6 Improve price research queries
CI / test (push) Successful in 1m8s
CI / test (pull_request) Successful in 1m13s
2026-08-25 11:01:22 +03:00
m 98cf218cc3 Merge pull request 'Shorten research source labels' (#336) from codex/chat-semantic-inventory into main
CI / test (push) Successful in 1m16s
2026-08-25 07:58:42 +00:00
m 7abe73e7bd Shorten research source labels
CI / test (push) Successful in 1m5s
CI / test (pull_request) Successful in 1m8s
2026-08-25 10:55:07 +03:00
m a05ddacff3 Merge pull request 'Clarify research results without price evidence' (#335) from codex/chat-semantic-inventory into main
CI / test (push) Successful in 1m17s
2026-08-25 07:52:31 +00:00
m 20b18de60a Clarify missing price evidence
CI / test (push) Successful in 1m3s
CI / test (pull_request) Successful in 1m8s
2026-08-25 10:49:34 +03:00
m d5c98dd62f Merge pull request 'Preserve durable assistant identity and deterministic replies' (#334) from codex/chat-semantic-inventory into main
CI / test (push) Successful in 1m15s
2026-08-25 07:42:01 +00:00
4 changed files with 45 additions and 6 deletions
+11 -1
View File
@@ -81,7 +81,8 @@ func (c SearchConnector) collectEndpoint(ctx context.Context, configured SearchE
if !strings.Contains(configured.Template, "%s") {
return nil, ErrSearchRejected
}
endpoint, err := url.Parse(strings.Replace(configured.Template, "%s", url.QueryEscape(strings.TrimSpace(request.Query)), 1))
searchQuery := enrichedSearchQuery(request.Query)
endpoint, err := url.Parse(strings.Replace(configured.Template, "%s", url.QueryEscape(searchQuery), 1))
if err != nil || endpoint.Scheme != "https" || endpoint.Host == "" || !allowedHost(configured.AllowedHosts, strings.ToLower(endpoint.Hostname())) {
return nil, ErrSearchRejected
}
@@ -204,6 +205,15 @@ func hasNumericSearchTerm(values []string) bool {
return false
}
func enrichedSearchQuery(query string) string {
trimmed := strings.TrimSpace(query)
lower := strings.ToLower(trimmed)
if (strings.Contains(lower, "цен") || strings.Contains(lower, "стоим")) && !strings.Contains(lower, "куп") {
return trimmed + " цена купить сегодня"
}
return trimmed
}
func allowedHost(hosts map[string]struct{}, host string) bool { _, ok := hosts[host]; return ok }
func (c SearchConnector) limit() int {
if c.MaxResults <= 0 || c.MaxResults > 8 {
@@ -46,3 +46,12 @@ func TestSearchConnectorFallsBackToAnotherAllowedSource(t *testing.T) {
t.Fatalf("search result source = %#v", results[0].Source)
}
}
func TestEnrichedSearchQueryAddsPriceSignalsOnlyToPriceRequests(t *testing.T) {
if got := enrichedSearchQuery("проверь цену на видеокарту 4090"); got != "проверь цену на видеокарту 4090 цена купить сегодня" {
t.Fatalf("price query = %q", got)
}
if got := enrichedSearchQuery("какая погода в Казани"); got != "какая погода в Казани" {
t.Fatalf("non-price query = %q", got)
}
}
+16 -5
View File
@@ -30,6 +30,7 @@ import (
"log"
"net/http"
"os"
"regexp"
"sort"
"strconv"
"strings"
@@ -747,7 +748,7 @@ func main() {
PropositionKey: fmt.Sprintf("question:%s:%d", utterance.ID, index), Query: part,
})
cancelResearch()
reply, backed := renderResearchReply(result, researchErr)
reply, backed := renderResearchReply(part, result, researchErr)
if backed {
researchBacked = true
}
@@ -1625,7 +1626,7 @@ func hasCapabilityHint(hints []string, wanted string) bool {
return false
}
func renderResearchReply(result epistemics.ResearchResult, researchErr error) (string, bool) {
func renderResearchReply(query string, result epistemics.ResearchResult, researchErr error) (string, bool) {
if researchErr != nil {
return "Сейчас не удалось получить данные из подключённого источника. Попробую снова через доступный маршрут.", false
}
@@ -1650,7 +1651,17 @@ func renderResearchReply(result epistemics.ResearchResult, researchErr error) (s
if len(lines) == 0 {
return "Проверяемых данных пока не найдено. Могу повторить поиск или уточнить, что именно проверить.", false
}
return strings.Join(lines, "\n"), true
reply := strings.Join(lines, "\n")
lowerQuery := strings.ToLower(query)
if (strings.Contains(lowerQuery, "цен") || strings.Contains(lowerQuery, "стоим")) && !containsPriceEvidence(reply) {
reply = "Актуальная цена в найденных фрагментах не указана, поэтому не буду придумывать сумму. Вот страницы, где её можно проверить:\n" + reply
}
return reply, true
}
func containsPriceEvidence(value string) bool {
pricePattern := regexp.MustCompile(`(?i)(\d[\d\s.,]{2,})(?:\s*(?:₽|руб\.?|р\.?|usd|\$|€))`)
return pricePattern.MatchString(value)
}
func reviewPreservesResearchEvidence(reviewed, draft string) bool {
@@ -1716,9 +1727,9 @@ func researchSourceLabel(finding epistemics.ResearchFinding) string {
}
if title != "" && publisher != "" {
if locator != "" {
return title + " — " + publisher + " (" + locator + ")"
return publisher + " (" + locator + ")"
}
return title + " — " + publisher
return publisher
}
if title != "" {
return title
+9
View File
@@ -48,6 +48,15 @@ func TestHumanMemoryInventoryUsesNewestPreference(t *testing.T) {
}
}
func TestContainsPriceEvidenceDistinguishesLinksFromPrices(t *testing.T) {
if containsPriceEvidence("RTX 4090 — market.yandex.ru") {
t.Fatal("a product link is not price evidence")
}
if !containsPriceEvidence("Цена: 189 990 ₽") {
t.Fatal("expected a currency amount to count as price evidence")
}
}
func TestCognitiveChannelQuestionUsesHumanSafeHealthReply(t *testing.T) {
reply := humanCognitiveChannelReply(interaction.InformationRequestCognitiveChannelStatus, interaction.SpeechActQuestion, capability.Health{State: capability.HealthAvailable, CapabilityID: "provider-secret-model"}, nil)
if !strings.Contains(reply, "доступен") || strings.Contains(reply, "provider-secret-model") {