Усилить семантический AGENT gate для 1С

This commit is contained in:
2026-05-23 22:01:29 +03:00
parent 75e0e2c66e
commit a4dd9c7c66
9 changed files with 634 additions and 13 deletions
@@ -381,6 +381,9 @@ function hasValueFlowActionConflictWithDiscoveryTurnMeaning(input, entryPoint) {
if (askedDomain !== "counterparty_value") {
return false;
}
if (askedAction === "net_value_flow") {
return true;
}
if (hasExactBankOperationsAddressReply(input, entryPoint)) {
return false;
}
@@ -388,9 +391,6 @@ function hasValueFlowActionConflictWithDiscoveryTurnMeaning(input, entryPoint) {
if (askedAction === "payout") {
return detectedIntent !== "supplier_payouts_profile";
}
if (askedAction === "net_value_flow") {
return true;
}
return false;
}
function hasEvidenceLaneConflictWithDiscoveryTurnMeaning(input, entryPoint) {
@@ -534,6 +534,10 @@ function hasSemanticConflictWithDiscoveryTurnMeaning(input, entryPoint) {
return false;
}
if (hasExactBankOperationsAddressReply(input, entryPoint)) {
const askedAction = toNonEmptyString(readDiscoveryTurnMeaning(entryPoint)?.asked_action_family);
if (askedAction === "net_value_flow") {
return true;
}
return false;
}
const detectedIntent = toNonEmptyString(input.addressRuntimeMeta?.detected_intent);
@@ -644,6 +648,9 @@ function applyAssistantMcpDiscoveryResponsePolicy(input) {
const metadataDiscoveryPriority = hasMetadataDiscoveryPriority(input, entryPoint);
const valueFlowActionConflictWithDiscoveryTurnMeaning = hasValueFlowActionConflictWithDiscoveryTurnMeaning(input, entryPoint);
const evidenceLaneConflictWithDiscoveryTurnMeaning = hasEvidenceLaneConflictWithDiscoveryTurnMeaning(input, entryPoint);
const exactBankOperationsProtectsCurrent = exactBankOperationsAddressReply &&
!semanticConflictWithDiscoveryTurnMeaning &&
!valueFlowActionConflictWithDiscoveryTurnMeaning;
if (!entryPoint) {
pushReason(reasonCodes, "mcp_discovery_response_policy_no_entry_point");
}
@@ -701,7 +708,7 @@ function applyAssistantMcpDiscoveryResponsePolicy(input) {
if (exactValueFlowReplyForBusinessOverviewDirectMoneyNeed) {
pushReason(reasonCodes, "mcp_discovery_response_policy_keep_exact_value_flow_reply_over_business_overview_direct_money_clarification");
}
if (exactBankOperationsAddressReply) {
if (exactBankOperationsProtectsCurrent) {
pushReason(reasonCodes, "mcp_discovery_response_policy_keep_exact_bank_operations_address_reply");
}
if (inventoryMarginRankingAddressReply) {
@@ -736,7 +743,7 @@ function applyAssistantMcpDiscoveryResponsePolicy(input) {
!runtimeMatchedExactReply &&
!staleMetadataDiscoveryFallbackAgainstExactAddressReply &&
!exactValueFlowReplyForBusinessOverviewDirectMoneyNeed &&
!exactBankOperationsAddressReply &&
!exactBankOperationsProtectsCurrent &&
!inventoryMarginRankingAddressReply &&
!(deterministicBroadBusinessEvaluationReply && candidate.candidate_status === "clarification_candidate") &&
ALLOWED_CANDIDATE_STATUSES.has(candidate.candidate_status) &&
@@ -537,6 +537,9 @@ function hasValueFlowActionConflictWithDiscoveryTurnMeaning(
if (askedDomain !== "counterparty_value") {
return false;
}
if (askedAction === "net_value_flow") {
return true;
}
if (hasExactBankOperationsAddressReply(input, entryPoint)) {
return false;
}
@@ -544,9 +547,6 @@ function hasValueFlowActionConflictWithDiscoveryTurnMeaning(
if (askedAction === "payout") {
return detectedIntent !== "supplier_payouts_profile";
}
if (askedAction === "net_value_flow") {
return true;
}
return false;
}
@@ -726,6 +726,10 @@ function hasSemanticConflictWithDiscoveryTurnMeaning(
return false;
}
if (hasExactBankOperationsAddressReply(input, entryPoint)) {
const askedAction = toNonEmptyString(readDiscoveryTurnMeaning(entryPoint)?.asked_action_family);
if (askedAction === "net_value_flow") {
return true;
}
return false;
}
const detectedIntent = toNonEmptyString(input.addressRuntimeMeta?.detected_intent);
@@ -870,6 +874,10 @@ export function applyAssistantMcpDiscoveryResponsePolicy(
input,
entryPoint
);
const exactBankOperationsProtectsCurrent =
exactBankOperationsAddressReply &&
!semanticConflictWithDiscoveryTurnMeaning &&
!valueFlowActionConflictWithDiscoveryTurnMeaning;
if (!entryPoint) {
pushReason(reasonCodes, "mcp_discovery_response_policy_no_entry_point");
@@ -940,7 +948,7 @@ export function applyAssistantMcpDiscoveryResponsePolicy(
"mcp_discovery_response_policy_keep_exact_value_flow_reply_over_business_overview_direct_money_clarification"
);
}
if (exactBankOperationsAddressReply) {
if (exactBankOperationsProtectsCurrent) {
pushReason(reasonCodes, "mcp_discovery_response_policy_keep_exact_bank_operations_address_reply");
}
if (inventoryMarginRankingAddressReply) {
@@ -980,7 +988,7 @@ export function applyAssistantMcpDiscoveryResponsePolicy(
!runtimeMatchedExactReply &&
!staleMetadataDiscoveryFallbackAgainstExactAddressReply &&
!exactValueFlowReplyForBusinessOverviewDirectMoneyNeed &&
!exactBankOperationsAddressReply &&
!exactBankOperationsProtectsCurrent &&
!inventoryMarginRankingAddressReply &&
!(deterministicBroadBusinessEvaluationReply && candidate.candidate_status === "clarification_candidate") &&
ALLOWED_CANDIDATE_STATUSES.has(candidate.candidate_status) &&
@@ -700,6 +700,67 @@ describe("assistant MCP discovery response policy", () => {
expect(result.reason_codes).not.toContain("mcp_discovery_response_policy_semantic_conflict_allows_candidate_override");
});
it("overrides exact bank operation replies for explicit counterparty received-paid-net questions", () => {
const result = applyAssistantMcpDiscoveryResponsePolicy({
currentReply:
"Exact bank operation answer: found 13 bank operations for Group SVK, showing rows and payment purposes.",
currentReplySource: "address_query_runtime_v1",
currentReplyType: "factual",
addressRuntimeMeta: {
detected_intent: "bank_operations_by_counterparty",
selected_recipe: "address_bank_operations_by_counterparty_v1",
mcp_call_status: "matched_non_empty",
capability_route_mode: "exact",
answer_grounding_check: {
status: "grounded"
},
assistant_mcp_discovery_entry_point_v1: entryPoint({
turn_input: {
adapter_status: "ready",
should_run_discovery: true,
data_need_graph: {
business_fact_family: "value_flow",
subject_candidates: ["Group SVK"],
reason_codes: ["data_need_graph_built", "data_need_graph_bidirectional_value_flow"]
},
turn_meaning_ref: {
asked_domain_family: "counterparty_value",
asked_action_family: "net_value_flow",
explicit_entity_candidates: ["Group SVK"],
explicit_date_scope: "2020",
unsupported_but_understood_family: "counterparty_bidirectional_value_flow_or_netting"
}
},
bridge: {
bridge_status: "answer_draft_ready",
user_facing_response_allowed: true,
business_fact_answer_allowed: true,
requires_user_clarification: false,
answer_draft: {
answer_mode: "confirmed_with_bounded_inference",
headline: "Group SVK 2020: received 12 093 465 rub., paid 0 rub.; net 12 093 465 rub. toward us.",
confirmed_lines: ["received 12 093 465 rub.; paid 0 rub.; net 12 093 465 rub."],
inference_lines: [],
unknown_lines: [],
limitation_lines: [],
next_step_line: null
}
}
})
}
});
expect(result.applied).toBe(true);
expect(result.decision).toBe("apply_candidate");
expect(result.reply_source).toBe("mcp_discovery_response_candidate_guarded");
expect(result.reply_text).toContain("received 12 093 465");
expect(result.reply_text).toContain("paid 0");
expect(result.reply_text).toContain("net 12 093 465");
expect(result.reason_codes).toContain("mcp_discovery_response_policy_value_flow_action_conflict_allows_candidate_override");
expect(result.reason_codes).toContain("mcp_discovery_response_policy_semantic_conflict_allows_candidate_override");
expect(result.reason_codes).not.toContain("mcp_discovery_response_policy_keep_exact_bank_operations_address_reply");
});
it("overrides an exact ranking-shaped address reply when open-scope ranking still needs organization", () => {
const result = applyAssistantMcpDiscoveryResponsePolicy({
currentReply:
@@ -1,4 +1,84 @@
[
{
"generation_id": "gen-ag05231858-323f86",
"created_at": "2026-05-23T18:58:48+00:00",
"mode": "saved_user_sessions",
"title": "AGENT | Autonomy business quality pack",
"count": 15,
"domain": "autonomy_business_quality",
"questions": [
"Сколько входящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?",
"Сколько исходящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?",
"А всего сколько денег пришло в ООО Альтернатива Плюс за 2020, без топов и без контрагентов?",
"Теперь дай взрослый обзор за 2020 по компании: входящие, исходящие, нетто, топы, но банк в топах отдельно объясни как финансовый поток.",
"скока денег альтернатива заработала за 20 год?",
"а это чистая прибыль?",
"Какая чистая прибыль по ООО Альтернатива Плюс за 2020?",
"А отдельно по СБЕРБАНКУ: он для нас клиент, поставщик или финансовый поток? Дай коротко по подтвержденным строкам.",
"какое нетто по деньгам с Группа СВК за 2020 год: сколько получили и сколько заплатили?",
"кому мы должны на конец 2020?",
"а нам кто должен на конец 2020?",
"сколько НДС надо заплатить в налоговую за декабрь 2019?",
"Как ты оценишь деятельность компании?",
"Какая номенклатура товара реализована с высокой прибылью какая с низкой?",
"май 2020"
],
"generated_by": "codex_agent",
"saved_case_set_file": "assistant_autogen_saved_user_sessions_20260523185848_gen-ag05231858-323f86.json",
"context": {
"llm_provider": null,
"model": null,
"assistant_prompt_version": null,
"decomposition_prompt_version": null,
"prompt_fingerprint": null,
"autogen_personality_id": null,
"autogen_personality_prompt": null,
"source_session_id": null,
"saved_session_file": "assistant_saved_session_20260523185848_gen-ag05231858-323f86.json",
"saved_case_set_kind": "agent_semantic_scenario",
"agent_run": true,
"agent_focus": "Expanded targeted AGENT replay for the autonomy milestone: value-flow, business overview, debts, VAT, profit/cashflow distinction, nomenclature margin boundary, and final answer quality must survive realistic business questions.",
"architecture_phase": "turnaround_11",
"source_spec_file": "X:\\1C\\NDC_1C\\docs\\orchestration\\agent_autonomy_business_quality_20260523.json",
"scenario_id": "agent_autonomy_business_quality_20260523",
"semantic_tags": [
"autonomy_core",
"bank_boundary",
"bank_classification",
"business_answer_quality",
"business_evaluation",
"business_overview",
"cashflow_overview",
"cashflow_vs_profit",
"clarification",
"colloquial_money",
"colloquial_total",
"counterparty_value_flow",
"debt_answer_quality",
"direct_profit",
"domain_purity",
"followup_context",
"incoming_total",
"limit_honesty",
"limited_answer",
"net_flow",
"next_action",
"no_profit_substitution",
"no_top_guard",
"nomenclature_margin",
"outgoing_total",
"payables",
"profit_vs_cashflow",
"receivables",
"technical_garbage_guard",
"value_flow",
"vat"
],
"validation_status": "accepted_live_replay",
"validated_run_dir": "artifacts\\domain_runs\\agent_autonomy_business_quality_live_semantic_gate_accepted_20260523",
"saved_after_validated_replay": true
}
},
{
"generation_id": "gen-ag05231427-70915a",
"created_at": "2026-05-23T14:27:55+00:00",
@@ -0,0 +1,287 @@
{
"saved_at": "2026-05-23T18:58:48+00:00",
"generation_id": "gen-ag05231858-323f86",
"mode": "saved_user_sessions",
"title": "AGENT | Autonomy business quality pack",
"agent_run": true,
"questions": [
"Сколько входящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?",
"Сколько исходящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?",
"А всего сколько денег пришло в ООО Альтернатива Плюс за 2020, без топов и без контрагентов?",
"Теперь дай взрослый обзор за 2020 по компании: входящие, исходящие, нетто, топы, но банк в топах отдельно объясни как финансовый поток.",
"скока денег альтернатива заработала за 20 год?",
"а это чистая прибыль?",
"Какая чистая прибыль по ООО Альтернатива Плюс за 2020?",
"А отдельно по СБЕРБАНКУ: он для нас клиент, поставщик или финансовый поток? Дай коротко по подтвержденным строкам.",
"какое нетто по деньгам с Группа СВК за 2020 год: сколько получили и сколько заплатили?",
"кому мы должны на конец 2020?",
"а нам кто должен на конец 2020?",
"сколько НДС надо заплатить в налоговую за декабрь 2019?",
"Как ты оценишь деятельность компании?",
"Какая номенклатура товара реализована с высокой прибылью какая с низкой?",
"май 2020"
],
"metadata": {
"assistant_prompt_version": null,
"decomposition_prompt_version": null,
"prompt_fingerprint": null,
"agent_focus": "Expanded targeted AGENT replay for the autonomy milestone: value-flow, business overview, debts, VAT, profit/cashflow distinction, nomenclature margin boundary, and final answer quality must survive realistic business questions.",
"architecture_phase": "turnaround_11",
"source_spec_file": "X:\\1C\\NDC_1C\\docs\\orchestration\\agent_autonomy_business_quality_20260523.json",
"scenario_id": "agent_autonomy_business_quality_20260523",
"semantic_tags": [
"autonomy_core",
"bank_boundary",
"bank_classification",
"business_answer_quality",
"business_evaluation",
"business_overview",
"cashflow_overview",
"cashflow_vs_profit",
"clarification",
"colloquial_money",
"colloquial_total",
"counterparty_value_flow",
"debt_answer_quality",
"direct_profit",
"domain_purity",
"followup_context",
"incoming_total",
"limit_honesty",
"limited_answer",
"net_flow",
"next_action",
"no_profit_substitution",
"no_top_guard",
"nomenclature_margin",
"outgoing_total",
"payables",
"profit_vs_cashflow",
"receivables",
"technical_garbage_guard",
"value_flow",
"vat"
],
"validation_status": "accepted_live_replay",
"validated_run_dir": "artifacts\\domain_runs\\agent_autonomy_business_quality_live_semantic_gate_accepted_20260523",
"saved_after_validated_replay": true,
"save_gate": {
"schema_version": "agent_semantic_save_gate_v1",
"validation_status": "accepted_live_replay",
"validated_run_dir": "artifacts\\domain_runs\\agent_autonomy_business_quality_live_semantic_gate_accepted_20260523",
"final_status": "accepted",
"review_overall_status": "pass",
"business_overall_status": "pass",
"steps_total": 15,
"steps_passed": 15,
"steps_failed": 0,
"steps_with_business_failures": 0,
"steps_with_business_warnings": 0,
"acceptance_gate_passed": true,
"saved_after_validated_replay": true
}
},
"source_session_id": null,
"session": {
"session_id": null,
"mode": "agent_semantic_run",
"items": [
{
"message_id": "agent-user-001",
"role": "user",
"text": "Сколько входящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-002",
"role": "user",
"text": "Сколько исходящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-003",
"role": "user",
"text": "А всего сколько денег пришло в ООО Альтернатива Плюс за 2020, без топов и без контрагентов?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-004",
"role": "user",
"text": "Теперь дай взрослый обзор за 2020 по компании: входящие, исходящие, нетто, топы, но банк в топах отдельно объясни как финансовый поток.",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-005",
"role": "user",
"text": "скока денег альтернатива заработала за 20 год?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-006",
"role": "user",
"text": "а это чистая прибыль?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-007",
"role": "user",
"text": "Какая чистая прибыль по ООО Альтернатива Плюс за 2020?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-008",
"role": "user",
"text": "А отдельно по СБЕРБАНКУ: он для нас клиент, поставщик или финансовый поток? Дай коротко по подтвержденным строкам.",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-009",
"role": "user",
"text": "какое нетто по деньгам с Группа СВК за 2020 год: сколько получили и сколько заплатили?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-010",
"role": "user",
"text": "кому мы должны на конец 2020?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-011",
"role": "user",
"text": "а нам кто должен на конец 2020?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-012",
"role": "user",
"text": "сколько НДС надо заплатить в налоговую за декабрь 2019?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-013",
"role": "user",
"text": "Как ты оценишь деятельность компании?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-014",
"role": "user",
"text": "Какая номенклатура товара реализована с высокой прибылью какая с низкой?",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
},
{
"message_id": "agent-user-015",
"role": "user",
"text": "май 2020",
"created_at": "2026-05-23T18:58:48+00:00",
"reply_type": null,
"trace_id": null,
"debug": null
}
],
"agent_run": true,
"metadata": {
"assistant_prompt_version": null,
"decomposition_prompt_version": null,
"prompt_fingerprint": null,
"agent_focus": "Expanded targeted AGENT replay for the autonomy milestone: value-flow, business overview, debts, VAT, profit/cashflow distinction, nomenclature margin boundary, and final answer quality must survive realistic business questions.",
"architecture_phase": "turnaround_11",
"source_spec_file": "X:\\1C\\NDC_1C\\docs\\orchestration\\agent_autonomy_business_quality_20260523.json",
"scenario_id": "agent_autonomy_business_quality_20260523",
"semantic_tags": [
"autonomy_core",
"bank_boundary",
"bank_classification",
"business_answer_quality",
"business_evaluation",
"business_overview",
"cashflow_overview",
"cashflow_vs_profit",
"clarification",
"colloquial_money",
"colloquial_total",
"counterparty_value_flow",
"debt_answer_quality",
"direct_profit",
"domain_purity",
"followup_context",
"incoming_total",
"limit_honesty",
"limited_answer",
"net_flow",
"next_action",
"no_profit_substitution",
"no_top_guard",
"nomenclature_margin",
"outgoing_total",
"payables",
"profit_vs_cashflow",
"receivables",
"technical_garbage_guard",
"value_flow",
"vat"
],
"validation_status": "accepted_live_replay",
"validated_run_dir": "artifacts\\domain_runs\\agent_autonomy_business_quality_live_semantic_gate_accepted_20260523",
"saved_after_validated_replay": true,
"save_gate": {
"schema_version": "agent_semantic_save_gate_v1",
"validation_status": "accepted_live_replay",
"validated_run_dir": "artifacts\\domain_runs\\agent_autonomy_business_quality_live_semantic_gate_accepted_20260523",
"final_status": "accepted",
"review_overall_status": "pass",
"business_overall_status": "pass",
"steps_total": 15,
"steps_passed": 15,
"steps_failed": 0,
"steps_with_business_failures": 0,
"steps_with_business_warnings": 0,
"acceptance_gate_passed": true,
"saved_after_validated_replay": true
}
}
}
}
@@ -0,0 +1,70 @@
{
"suite_id": "assistant_saved_session_gen-ag05231858-323f86",
"suite_version": "0.1.0",
"schema_version": "assistant_saved_session_suite_v0_1",
"generated_at": "2026-05-23T18:58:48+00:00",
"generation_id": "gen-ag05231858-323f86",
"mode": "saved_user_sessions",
"title": "AGENT | Autonomy business quality pack",
"domain": "autonomy_business_quality",
"scenario_count": 1,
"case_ids": [
"SAVED-001"
],
"cases": [
{
"case_id": "SAVED-001",
"scenario_tag": "agent_saved_user_sessions",
"title": "AGENT | Autonomy business quality pack",
"question_type": "followup",
"broadness_level": "medium",
"turns": [
{
"user_message": "Сколько входящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?"
},
{
"user_message": "Сколько исходящих денег за 2020 год по ООО Альтернатива Плюс без разреза по контрагентам?"
},
{
"user_message": "А всего сколько денег пришло в ООО Альтернатива Плюс за 2020, без топов и без контрагентов?"
},
{
"user_message": "Теперь дай взрослый обзор за 2020 по компании: входящие, исходящие, нетто, топы, но банк в топах отдельно объясни как финансовый поток."
},
{
"user_message": "скока денег альтернатива заработала за 20 год?"
},
{
"user_message": "а это чистая прибыль?"
},
{
"user_message": "Какая чистая прибыль по ООО Альтернатива Плюс за 2020?"
},
{
"user_message": "А отдельно по СБЕРБАНКУ: он для нас клиент, поставщик или финансовый поток? Дай коротко по подтвержденным строкам."
},
{
"user_message": "какое нетто по деньгам с Группа СВК за 2020 год: сколько получили и сколько заплатили?"
},
{
"user_message": "кому мы должны на конец 2020?"
},
{
"user_message": "а нам кто должен на конец 2020?"
},
{
"user_message": "сколько НДС надо заплатить в налоговую за декабрь 2019?"
},
{
"user_message": "Как ты оценишь деятельность компании?"
},
{
"user_message": "Какая номенклатура товара реализована с высокой прибылью какая с низкой?"
},
{
"user_message": "май 2020"
}
]
}
]
}