DeepAgent module
DeepAgent
Bases: Module
A coding agent with filesystem and shell access scoped to a workdir.
DeepAgent is a thin specialization of :class:FunctionCallingAgent
that pre-wires up to six workspace tools:
read_file: read a file with line-based pagination, output prefixed with 1-based line numbers (cat -nstyle).list_directory: list entries in a directory.search_files: glob for files and optionally grep their contents (regex). Combines find and grep in one call.write_file: overwrite or create a file (gated byallow_write).edit_file: exact-string replacement, one occurrence at a time (gated byallow_write).run_bash: run a shell command (gated byallow_bash).
The constructor mirrors :class:FunctionCallingAgent — every
parameter on that class is accepted here with identical semantics.
The only additions are workdir (required) and the safety
knobs: allow_write, allow_bash, timeout,
max_output_chars. User-supplied tools are appended to the
built-in ones.
Security model
File tools (read_file / write_file / edit_file /
list_directory) refuse any path that resolves outside the
workdir, including .. traversal and absolute paths. Paths are
canonicalized via Path.resolve() (which flattens .. and
follows existing symlinks) and then prefix-checked against the
resolved workdir, so a symlink-inside-workdir pointing to
/etc/passwd is also caught. File opens use O_NOFOLLOW
where the OS supports it as defense in depth against TOCTOU
symlink swaps.
The bash tool is NOT sandboxed. Its cwd is the workdir,
but the shell can still read or write any path the host process
can. If you're running this on untrusted input, run the host
process inside a container or other OS-level isolation; the
Python layer cannot make run_bash safe on its own. Disable
it with allow_bash=False when you don't need it.
Example:
import synalinks
import asyncio
async def main():
lm = synalinks.LanguageModel(model="ollama/mistral")
inputs = synalinks.Input(data_model=synalinks.ChatMessages)
outputs = await synalinks.DeepAgent(
workdir="/tmp/my_project",
language_model=lm,
)(inputs)
agent = synalinks.Program(inputs=inputs, outputs=outputs)
messages = synalinks.ChatMessages(messages=[
synalinks.ChatMessage(
role="user",
content="What's in this directory?",
)
])
result = await agent(messages)
print(result.get("messages")[-1].get("content"))
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
str
|
Working directory the agent operates in. Required. Must exist. All file paths supplied by the LM are resolved relative to it and rejected if they escape. |
required |
allow_write
|
bool
|
When |
True
|
allow_bash
|
bool
|
When |
True
|
timeout
|
float
|
Per-command bash timeout in seconds. Defaults to 30. |
30.0
|
max_output_chars
|
int
|
Cap on characters returned per
stream from |
10000
|
max_search_results
|
int
|
Cap on entries returned by
|
100
|
tools
|
list
|
Additional :class: |
None
|
schema
|
dict
|
JSON schema for the final answer. |
None
|
data_model
|
DataModel
|
DataModel for the final answer.
Mutually exclusive with |
None
|
language_model
|
LanguageModel
|
The language model that drives the agent loop. |
None
|
prompt_template
|
str
|
Forwarded to the tool-call generator. |
None
|
examples
|
list
|
Few-shot examples for the tool-call generator. |
None
|
instructions
|
str
|
Override the default system instructions. When omitted, the default is built from the workdir and the configured permissions. |
None
|
final_instructions
|
str
|
Instructions for the final-answer
generator. Defaults to |
None
|
temperature
|
float
|
LM sampling temperature. Defaults to 0.0. |
0.0
|
use_inputs_schema
|
bool
|
Include the input schema in the prompt. |
False
|
use_outputs_schema
|
bool
|
Include the output schema in the prompt. |
False
|
reasoning_effort
|
str
|
Forwarded to the generators (for reasoning-capable LMs). |
None
|
use_chain_of_thought
|
bool
|
When |
False
|
autonomous
|
bool
|
When |
True
|
return_inputs_with_trajectory
|
bool
|
When |
True
|
max_iterations
|
int
|
Maximum number of tool-call rounds. Defaults to 10 (coding tasks tend to need more rounds than RAG / SQL). |
10
|
streaming
|
bool
|
Stream the final answer when no |
False
|
name
|
str
|
Module name. |
None
|
description
|
str
|
Module description. |
None
|
Source code in synalinks/src/modules/agents/deep_agent.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | |
PathTraversalError
get_default_instructions(workdir, allow_write, allow_bash)
Default system instructions for the deep agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
str
|
Absolute path of the agent's working directory. Embedded in the prompt so the LM knows where it's operating. |
required |
allow_write
|
bool
|
Whether write/edit tools are enabled. |
required |
allow_bash
|
bool
|
Whether the bash tool is enabled. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A prompt string describing the tool plan and the safety |
str
|
constraints currently in effect. |