1. Go to this page and download the library: Download jvjvjv/code-talker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Jvjvjv\CodeTalker\Services\LaravelAi\AgentFactory;
use Jvjvjv\CodeTalker\Models\AiSystem;
// From a specific system record
$agent = app(AgentFactory::class)->forSystem(
AiSystem::find($id),
instructions: 'You are a helpful assistant.',
maxTokens: 2048,
temperature: 0.7,
);
// From a feature key (resolves the default system for that feature)
$agent = app(AgentFactory::class)->forFeature('my-feature');
$response = $agent->prompt('Hello!'); // Laravel\Ai\Responses\AgentResponse
echo $response->text;
foreach ($agent->stream('Hello!') as $event) {
// Laravel\Ai\Streaming\Events\* (TextDelta, ToolCall, StreamEnd, ...)
}
// Start it. Returns an AiTurnRun; `public_id` is the handle to put in a URL.
$run = $chat->dispatchTurn($conversation, $request->string('message')->toString());
// Stream it — from the start, or from wherever the browser left off.
foreach ($encoder->encode($chat->resumeTurn($run, $after)) as $frame) {
echo $frame;
ob_get_level() > 0 && ob_flush();
flush();
}
// Stop it early.
$chat->cancelTurn($run);
$presenter->transcript($conversation); // visible messages, system prompt excluded
// each row carries `incomplete` — see Interrupted turns
$presenter->totalCostUsd($persona); // lifetime cost for a persona
$presenter->conversationsFor($user, $personas); // an authenticated user's conversations
use Jvjvjv\CodeTalker\Jobs\RunAiOperatorJob;
// From anywhere that knows when this should run — an Eloquent observer, an
// event listener, a console command, your own scheduled job:
dispatch(new RunAiOperatorJob($operator, [
'order' => $order->toArray(),
]));
// prompt_template: "A new order was placed: {{order.total}} for {{order.customer.email}}."
dispatch(new RunAiOperatorJob($operator, [
'order' => ['total' => 42, 'customer' => ['email' => '[email protected]']],
]));
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Jvjvjv\CodeTalker\Support\ToolContext;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\ResponseFactory;
use Laravel\Mcp\Server\Attributes\Description;
use Laravel\Mcp\Server\Attributes\Name;
use Laravel\Mcp\Server\Tool;
#[Name('get-weather')]
#[Description('Returns current weather for a given city.')]
class GetWeatherTool extends Tool
{
public function __construct(
private ToolContext $context,
) {}
public function schema(JsonSchema $schema): array
{
return [
'city' => $schema->string()->description('City name')->
use Jvjvjv\CodeTalker\CodeTalkerServiceProvider;
public function register(): void
{
CodeTalkerServiceProvider::addToolDirectory(
app_path('Services/Mcp/Tools'),
'App\\Services\\Mcp\\Tools\\'
);
}
use Jvjvjv\CodeTalker\Services\Management\AiSystemManager;
public function store(Request $request, AiSystemManager $systems)
{
$system = $systems->create($request->all());
return redirect()->route('your.systems.index');
}
public function rules(): array
{
return AiSystemManager::createRules($this->all());
}
$deactivatedBots = $systems->delete($system); // bots are deactivated, not deleted
$orphanedSystems = $prompts->delete($prompt); // systems have their prompt cleared
// config/code-talker.php
'schedule' => false,
// Your app's Console\Kernel or routes/console.php
Schedule::command('ai:sync-conversation-usage')->twiceDaily();