Skip to content

Commit 9931a3c

Browse files
committed
add subagent system prompt to chat history file for debugging
1 parent 6279701 commit 9931a3c

3 files changed

Lines changed: 104 additions & 11 deletions

File tree

packages/core/src/agents/executor.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
110110
private readonly compressionService: ChatCompressionService;
111111
private readonly summarizationService: SummarizationService;
112112
private hasFailedCompressionAttempt = false;
113+
private systemInstruction?: string;
113114

114115
/**
115116
* Creates and validates a new `AgentExecutor` instance.
@@ -174,6 +175,9 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
174175
): Promise<void> {
175176
const history = await chat.getHistory();
176177
let fileContent = 'Chat History\n\n';
178+
if (this.systemInstruction) {
179+
fileContent += `--- ROLE: system ---\n${this.systemInstruction}\n---\n\n`;
180+
}
177181
for (const message of history) {
178182
let content = '';
179183
for (const part of message?.parts ?? []) {
@@ -1085,34 +1089,34 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
10851089
);
10861090

10871091
// Build system instruction from the templated prompt string.
1088-
const systemInstruction = promptConfig.systemPrompt
1092+
this.systemInstruction = promptConfig.systemPrompt
10891093
? await this.buildSystemPrompt(inputs)
10901094
: undefined;
10911095

10921096
await fs.writeFile(
10931097
`${this.definition.name}_prompt.txt`,
1094-
systemInstruction ?? '',
1098+
this.systemInstruction ?? '',
10951099
);
10961100
debugLogger.log(
10971101
`[DEBUG] System Instruction saved to ${this.definition.name}_prompt.txt`,
10981102
);
10991103

11001104
// debugLogger.log(
1101-
// `[AgentExecutor] Created system instruction: ${systemInstruction}`,
1105+
// `[AgentExecutor] Created system instruction: ${this.systemInstruction}`,
11021106
// );
11031107

11041108
if ('host' in modelConfig) {
11051109
const populatedPromptConfig: PromptConfig = {
11061110
...promptConfig,
1107-
systemPrompt: systemInstruction ?? '',
1111+
systemPrompt: this.systemInstruction ?? '',
11081112
directive: this.definition.promptConfig.directive,
11091113
query: this.definition.promptConfig.query
11101114
? templateString(this.definition.promptConfig.query, inputs)
11111115
: 'Get Started!',
11121116
};
11131117
return new OllamaChat(
11141118
modelConfig as OllamaModelConfig,
1115-
systemInstruction,
1119+
this.systemInstruction,
11161120
startHistory,
11171121
populatedPromptConfig,
11181122
);
@@ -1127,8 +1131,8 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
11271131
},
11281132
};
11291133

1130-
if (systemInstruction) {
1131-
generationConfig.systemInstruction = systemInstruction;
1134+
if (this.systemInstruction) {
1135+
generationConfig.systemInstruction = this.systemInstruction;
11321136
}
11331137

11341138
return new GeminiChat(

prompt.txt

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,96 @@ comments.
484484

485485
Use hyphens instead of underscores in flag names (e.g. `my-flag` instead of
486486
`my_flag`).
487-
--- End of Context from: GEMINI.md ---
487+
--- End of Context from: GEMINI.md ---
488+
489+
--- Context from: litellm/GEMINI.md ---
490+
# GEMINI.md
491+
492+
This file provides guidance to Gemini when working with code in this repository.
493+
494+
## Development Commands
495+
496+
### Installation
497+
- `make install-dev` - Install core development dependencies
498+
- `make install-proxy-dev` - Install proxy development dependencies with full feature set
499+
- `make install-test-deps` - Install all test dependencies
500+
501+
### Testing
502+
- `make test` - Run all tests
503+
- `make test-unit` - Run unit tests (tests/test_litellm) with 4 parallel workers
504+
- `make test-integration` - Run integration tests (excludes unit tests)
505+
- `pytest tests/` - Direct pytest execution
506+
507+
### Code Quality
508+
- `make lint` - Run all linting (Ruff, MyPy, Black, circular imports, import safety)
509+
- `make format` - Apply Black code formatting
510+
- `make lint-ruff` - Run Ruff linting only
511+
- `make lint-mypy` - Run MyPy type checking only
512+
513+
### Single Test Files
514+
- `poetry run pytest tests/path/to/test_file.py -v` - Run specific test file
515+
- `poetry run pytest tests/path/to/test_file.py::test_function -v` - Run specific test
516+
517+
## Architecture Overview
518+
519+
LiteLLM is a unified interface for 100+ LLM providers with two main components:
520+
521+
### Core Library (`litellm/`)
522+
- **Main entry point**: `litellm/main.py` - Contains core completion() function
523+
- **Provider implementations**: `litellm/llms/` - Each provider has its own subdirectory
524+
- **Router system**: `litellm/router.py` + `litellm/router_utils/` - Load balancing and fallback logic
525+
- **Type definitions**: `litellm/types/` - Pydantic models and type hints
526+
- **Integrations**: `litellm/integrations/` - Third-party observability, caching, logging
527+
- **Caching**: `litellm/caching/` - Multiple cache backends (Redis, in-memory, S3, etc.)
528+
529+
### Proxy Server (`litellm/proxy/`)
530+
- **Main server**: `proxy_server.py` - FastAPI application
531+
- **Authentication**: `auth/` - API key management, JWT, OAuth2
532+
- **Database**: `db/` - Prisma ORM with PostgreSQL/SQLite support
533+
- **Management endpoints**: `management_endpoints/` - Admin APIs for keys, teams, models
534+
- **Pass-through endpoints**: `pass_through_endpoints/` - Provider-specific API forwarding
535+
- **Guardrails**: `guardrails/` - Safety and content filtering hooks
536+
- **UI Dashboard**: Served from `_experimental/out/` (Next.js build)
537+
538+
## Key Patterns
539+
540+
### Provider Implementation
541+
- Providers inherit from base classes in `litellm/llms/base.py`
542+
- Each provider has transformation functions for input/output formatting
543+
- Support both sync and async operations
544+
- Handle streaming responses and function calling
545+
546+
### Error Handling
547+
- Provider-specific exceptions mapped to OpenAI-compatible errors
548+
- Fallback logic handled by Router system
549+
- Comprehensive logging through `litellm/_logging.py`
550+
551+
### Configuration
552+
- YAML config files for proxy server (see `proxy/example_config_yaml/`)
553+
- Environment variables for API keys and settings
554+
- Database schema managed via Prisma (`proxy/schema.prisma`)
555+
556+
## Development Notes
557+
558+
### Code Style
559+
- Uses Black formatter, Ruff linter, MyPy type checker
560+
- Pydantic v2 for data validation
561+
- Async/await patterns throughout
562+
- Type hints required for all public APIs
563+
564+
### Testing Strategy
565+
- Unit tests in `tests/test_litellm/`
566+
- Integration tests for each provider in `tests/llm_translation/`
567+
- Proxy tests in `tests/proxy_unit_tests/`
568+
- Load tests in `tests/load_tests/`
569+
570+
### Database Migrations
571+
- Prisma handles schema migrations
572+
- Migration files auto-generated with `prisma migrate dev`
573+
- Always test migrations against both PostgreSQL and SQLite
574+
575+
### Enterprise Features
576+
- Enterprise-specific code in `enterprise/` directory
577+
- Optional features enabled via environment variables
578+
- Separate licensing and authentication for enterprise features
579+
--- End of Context from: litellm/GEMINI.md ---

understand.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ Using the codebase investigator: tell me how the ollama inference works.
248248
environment either due to prompt forgetting)
249249
1. Gemma often forgets which files it's already looked at.
250250

251-
1. executor.ts when saving chat history also save the system prompt. Call save
252-
chat history to file multiple times in the while loop so it updates with the
253-
terminal.
254251
1. Look at chat_history.txt. despite having a summary it still sees status 0 and
255252
decidesit doesn't have the full information.
256253

0 commit comments

Comments
 (0)