MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / UpstreamSemanticCompressor

Class UpstreamSemanticCompressor

uncommon_route/proxy.py:735–936  ·  view source on GitHub ↗

Runs semantic compression tasks through cheap upstream models.

Source from the content-addressed store, hash-verified

733
734
735class UpstreamSemanticCompressor:
736 """Runs semantic compression tasks through cheap upstream models."""
737
738 def __init__(
739 self,
740 *,
741 upstream_chat: str,
742 primary_api_key: str,
743 providers_config: ProvidersConfig,
744 model_mapper: ModelMapper,
745 composition_policy: CompositionPolicy,
746 ) -> None:
747 self._upstream_chat = upstream_chat
748 self._primary_api_key = primary_api_key
749 self._providers = providers_config
750 self._mapper = model_mapper
751 self._policy = composition_policy
752
753 def rebind_primary(
754 self,
755 *,
756 upstream_chat: str,
757 primary_api_key: str,
758 model_mapper: ModelMapper,
759 ) -> None:
760 self._upstream_chat = upstream_chat
761 self._primary_api_key = primary_api_key
762 self._mapper = model_mapper
763
764 def rebind_providers(self, providers_config: ProvidersConfig) -> None:
765 self._providers = providers_config
766
767 async def summarize_tool_result(
768 self,
769 content: str,
770 *,
771 tool_name: str,
772 latest_user_prompt: str,
773 request: Request,
774 ) -> SemanticCallResult | None:
775 system = (
776 "You compress tool outputs for another model. Preserve facts, paths, errors, "
777 "identifiers, counts, and anything actionable. Output plain text only."
778 )
779 user = (
780 f"Latest user goal:\n{latest_user_prompt}\n\n"
781 f"Tool: {tool_name or 'unknown'}\n"
782 "Summarize the following tool result for continuation in under 220 words.\n\n"
783 f"{content}"
784 )
785 return await self._run_task(
786 request,
787 self._policy.sidechannel.tool_summary,
788 system,
789 user,
790 source_text=content,
791 query_text=f"{latest_user_prompt} {tool_name}".strip(),
792 )

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected