diff --git a/agents/crypto_venture.py b/agents/crypto_venture.py index cc744fb..7f2568b 100644 --- a/agents/crypto_venture.py +++ b/agents/crypto_venture.py @@ -188,19 +188,22 @@ class CryptoVentureService: def regenerate_rejected_slots(self, cohort: VentureCohort, *, reason: str = "novelty_or_token_gate") -> list[CompanyProposal]: created = [] attempts = 0 - max_attempts = cohort.cohort_size * 3 + max_attempts = min(6, max(2, (cohort.cohort_size - cohort.members.count()) * 2)) while cohort.members.count() < cohort.cohort_size and attempts < max_attempts: attempts += 1 index = cohort.members.count() + attempts territory = CRYPTO_TERRITORIES[index % len(CRYPTO_TERRITORIES)] - payload, source = self._protocol_payload(index, territory) + if attempts <= 2: + payload, source = self._protocol_payload(index, territory) + else: + payload, source = self._fallback_payload(index, territory), "deterministic_crypto_repair" proposal = self._create_proposal(cohort.mandate, payload, source, territory) VentureCohortMember.objects.create(cohort=cohort, proposal=proposal, metadata={"territory": territory, "regenerated_for": reason}) created.append(proposal) self.assess_token_necessity(proposal) self.novelty_gate(cohort) self._remove_weak_token_members(cohort) - cohort.metrics = {**cohort.metrics, "regeneration_attempts": cohort.metrics.get("regeneration_attempts", 0) + attempts, "regenerated_protocols": cohort.metrics.get("regenerated_protocols", 0) + len(created), "accepted_protocols": cohort.members.count()} + cohort.metrics = {**cohort.metrics, "regeneration_attempts": cohort.metrics.get("regeneration_attempts", 0) + attempts, "regenerated_protocols": cohort.metrics.get("regenerated_protocols", 0) + len(created), "accepted_protocols": cohort.members.count(), "unfilled_slots_after_regeneration": max(0, cohort.cohort_size - cohort.members.count())} cohort.save(update_fields=["metrics", "updated_at"]) return created