<?phprequire'examples/boot.php';useCognesy\Addons\Chat\ChatFactory;useCognesy\Addons\Chat\Collections\Participants;useCognesy\Addons\Chat\Data\ChatState;useCognesy\Addons\Chat\Participants\LLMParticipant;useCognesy\Addons\Chat\Participants\ScriptedParticipant;useCognesy\Addons\Chat\Utils\SummarizeMessages;useCognesy\Addons\StepByStep\Continuation\ContinuationCriteria;useCognesy\Addons\StepByStep\Continuation\Criteria\ResponseContentCheck;useCognesy\Addons\StepByStep\Continuation\Criteria\StepsLimit;useCognesy\Addons\StepByStep\StateProcessing\Processors\AccumulateTokenUsage;useCognesy\Addons\StepByStep\StateProcessing\Processors\AppendStepMessages;useCognesy\Addons\StepByStep\StateProcessing\Processors\MoveMessagesToBuffer;useCognesy\Addons\StepByStep\StateProcessing\Processors\SummarizeBuffer;useCognesy\Addons\StepByStep\StateProcessing\StateProcessors;useCognesy\Events\Dispatchers\EventDispatcher;useCognesy\Messages\Messages;useCognesy\Polyglot\Inference\LLMProvider;$events=newEventDispatcher();$student=newScriptedParticipant(name:'student',messages:['Help me get better sales results.','What should I do next?','Give me one more actionable tip.','How could I apply this in practice?',"What are some common pitfalls to avoid?","Is there a specific mindset I should adopt?","Can you provide an example of a successful sales interaction using Challenger Sale?","How can I tailor my approach to different types of clients?","What questions should I be asking my prospects?","How do I handle objections effectively?","What should I focus on to improve my sales approach?","How can I measure the success of these strategies?","What resources can I use to learn more about Challenger Sale?","Any final advice for implementing these techniques effectively?",''// Empty string to signal end of conversation],);$expert=newLLMParticipant(name:'expert',llmProvider:LLMProvider::using('openai'),systemPrompt:'You are a helpful assistant explaining Challenger Sale. Be very brief (one sentence), pragmatic and focused on practical bizdev problems.');// Build a Chat with summary + buffer processors and an assistant participant$chat=ChatFactory::default(participants:newParticipants($student,$expert),continuationCriteria:newContinuationCriteria(newStepsLimit(30,fn(ChatState$state):int=>$state->stepCount()),newResponseContentCheck(fn(ChatState$state):?Messages=>$state->currentStep()?->outputMessages(),staticfn(Messages$lastResponse):bool=>$lastResponse->toString()!=='',),),processors:newStateProcessors(newAccumulateTokenUsage(),newAppendStepMessages(),newMoveMessagesToBuffer(maxTokens:128,bufferSection:'buffer',events:$events),newSummarizeBuffer(maxBufferTokens:128,maxSummaryTokens:512,bufferSection:'buffer',summarySection:'summary',summarizer:newSummarizeMessages(llm:LLMProvider::using('openai')),events:$events,),),events:$events,);//->wiretap(fn(Event $e) => $e->printDebug());$context="# CONTEXT\n\n".file_get_contents(__DIR__.'/summary.md');$state=(newChatState)->withMessages(Messages::fromString(content:$context,role:'system'));while($chat->hasNextStep($state)){$state=$chat->nextStep($state);$step=$state->currentStep();$name=$step?->participantName()??'unknown';$content=trim($step?->outputMessages()->toString()??'');echo"\n--- Step ".($state->stepCount())." ($name) ---\n";echo($content?:'[eot]')."\n";// echo "---------------------\n";// echo "SUMMARY:\n" . $state->store()->section('summary')->get()?->toString();// echo "---------------------\n";// echo "BUFFER:\n" . $state->store()->section('buffer')->get()?->toString();// echo "---------------------\n";// echo "MESSAGES:\n" . $state->store()->section('messages')->get()?->toString();// echo "=====================\n";}?>